Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SharedLocalizer and javascript in ASP.Net Core

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?

like image 342
ryan1555 Avatar asked Oct 29 '25 03:10

ryan1555


1 Answers

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);
}
like image 55
go.. Avatar answered Oct 31 '25 18:10

go..



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!