Decode and display string in View using JavaScript in ASP.Net MVC

Last Reply 26 days ago By anvina

Posted 26 days ago

In the view For vb code in the view I am setting a string with UTF-8 characters "Övriga frågor"

Then i assign this string to a javascript variable routers

But when the routerlist is assigned to routers the UTF-8 characters  are not the same.

The alert displays  the string as "Övriga frågor" some kind of encoding?

This javascript string is passed to server side vb code and I want to decode it back to the original string.

how can I do that?

Below is my code from a view in mvc

<div id='dashboardItemBody' style="align-content:center;width:100%;height:100%">
    @Html.Action("_getRouter2")
</div>

@section scripts  
    $(function () {
        var routers=  endmed "  + " @routerList ";
       alert(routers);
    });
</script>
end section

 

@Code 
   Dim  routerList as string = "Övriga frågor"
End Code

 

You are viewing reply posted by: anvina 26 days ago.
Posted 26 days ago

Found the answer in this thread!

thank you for your help!

If we use html raw then it will not encode

https://stackoverflow.com/questions/6291198/wrong-text-encoding-in-string-sent-to-javascript/6291236