4

I am using asp.net 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: enter image description here

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?

1 Answer 1

8

Returns markup that is not HTML encoded @Html.Raw

refactor

function updateCommission(agentID) {
    var msg = '@Html.Raw(SharedLocalizer["Confirm Update commission?"].Value.ToString())';
        return confirm(msg);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Great answer! Working with ASP.NET Core 3.1.6 and JS ES6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.