开发者

asp.net mvc. Inserting string data from model into javascript. best-practice

开发者 https://www.devze.com 2022-12-30 00:24 出处:网络
I have to populate javascript code in html layout (hidden fields, method params) with string data from model.开发者_如何转开发

I have to populate javascript code in html layout (hidden fields, method params) with string data from model.开发者_如何转开发

Html.Encode is not appropriate for my task because it encodes ' symbol, bypass : (that ruines object attributes declaration) and so on.

I wrote static helper class that is used from View like this:

  alert('<%=ViewHelper.MakeJavaScriptSafe(Model.Message)%>');

I hope there is asp.net in-built function I don't know about for this task. Does it exist really?

Thank you in advance.


I believe what you are looking for is an Anti-Cross Site Scripting library, like this one.

0

精彩评论

暂无评论...
验证码 换一张
取 消