最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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);
}
发布评论

评论列表(0)

  1. 暂无评论