c# - Using SharedLocalizer and javascript in ASP.Net Core - Stack Overflow

I am using asp core 2.0 to develop my MVC application. However, I am using the SharedLocalizer in the v

I am using asp core 2.0 to develop my MVC application. However, I am using the SharedLocalizer in the view. I use the following code to inject it:

@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.Extensions.Localization
@inject IViewLocalizer Localizer
@inject IStringLocalizer<SharedResources> SharedLocalizer
@inject IHtmlLocalizer<SharedResources> SharedHtmlLocalizer

This is how I call my SharedLocalizer:

function updateCommission(agentID) {
    var msg = '@SharedLocalizer["Confirm Update Commission?"].Value.ToString()';
    if (confirm(msg) == false)
        return false;
}

But, my result looks like this:

If I use the SharedLocalizer in my html label / input, it displays fine. When I view my page source, the string also is the '$#1231';

How can I display the correct string with my setup?

I am using asp core 2.0 to develop my MVC application. However, I am using the SharedLocalizer in the view. I use the following code to inject it:

@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.Extensions.Localization
@inject IViewLocalizer Localizer
@inject IStringLocalizer<SharedResources> SharedLocalizer
@inject IHtmlLocalizer<SharedResources> SharedHtmlLocalizer

This is how I call my SharedLocalizer:

function updateCommission(agentID) {
    var msg = '@SharedLocalizer["Confirm Update Commission?"].Value.ToString()';
    if (confirm(msg) == false)
        return false;
}

But, my result looks like this:

If I use the SharedLocalizer in my html label / input, it displays fine. When I view my page source, the string also is the '$#1231';

How can I display the correct string with my setup?

Share Improve this question edited Jul 24, 2020 at 10:13 andHapp 3,2072 gold badges23 silver badges21 bronze badges asked Oct 10, 2018 at 7:32 ryan1555ryan1555 1651 silver badge10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Returns markup that is not HTML encoded @Html.Raw

refactor

function updateCommission(agentID) {
    var msg = '@Html.Raw(SharedLocalizer["Confirm Update mission?"].Value.ToString())';
        return confirm(msg);
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745293623a4621011.html

相关推荐

  • c# - Using SharedLocalizer and javascript in ASP.Net Core - Stack Overflow

    I am using asp core 2.0 to develop my MVC application. However, I am using the SharedLocalizer in the v

    5小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信