How to encode embedded javascript in Razor view in ASP.NET MVC 3?
问题 How do I properly encode JavaScript in the following context: <html> ... <script type="text/javascript"> var settings = @Html.PleaseEncode(settings.ToJson()); // ... </script> </html> The values in my JSON objects are set by the application administrator, so I assume they need properly encoded -- both for HTML and JavaScript. I'm using System.Web.Script.Serialization.JavaScriptSerializer to do the JSON encoding. It looks like JavaScriptSerializer does some encoding as it outputs the text