简体   繁体   中英

Correctly escaping ° character from C# to javascript

I've found that special characters in an existing ASP.NET MVC application are not working correcly.

I need to escape from C# (those data arrives from DB)

The following string Quadri 3° e 4° livello

What I'm doing in the cshtml is

success: function (data) {

                    //alert(data);

                    var wnd;
                    var selector = $('#divImport_@id');

                    if (!selector.data("kendoWindow")) {
                        wnd = selector.kendoWindow({
                            title: "Import da file",
                            modal: true,
                            visible: false,
                            resizable: false,
                            width: 700,
                            deactivate: function () {
                                selector.empty();
                            }
                        }).data("kendoWindow");
                    }
                    else wnd = selector.data("kendoWindow");

                    wnd.title('Import da file - ' + decodeURIComponent('@HttpUtility.JavaScriptStringEncode(Model.NomeCategoria)'));
                    wnd.content(data);
                    wnd.center().open();
                }

What I got is the following output

在此处输入图像描述

How do I escape it correctly?

Thanks

Try with:

@Html.Raw(HttpUtility.JavaScriptStringEncode(Model.NomeCategoria))

as shown also here: Javascript, Razor and Escape characters. Like apostrophe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM