[英]asp.net mvc. Inserting string data from model into javascript. best-practice
I have to populate javascript code in html layout (hidden fields, method params) with string data from model. 我必须用模型中的字符串数据填充html布局(隐藏字段,方法参数)中的javascript代码。
Html.Encode
is not appropriate for my task because it encodes ' symbol, bypass : (that ruines object attributes declaration) and so on. Html.Encode
不适合我的任务,因为它会编码'符号,bypass :(破坏对象属性声明)等。
I wrote static helper class that is used from View like this: 我编写了从View中使用的静态帮助器类,如下所示:
alert('<%=ViewHelper.MakeJavaScriptSafe(Model.Message)%>');
I hope there is asp.net in-built function I don't know about for this task. 我希望有不知道此任务的asp.net内置函数。 Does it exist really?
它真的存在吗?
Thank you in advance. 先感谢您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.