asp.net mvc. Inserting string data from model into javascript. best-practice
Posted
by Andrew Florko
on Stack Overflow
See other posts from Stack Overflow
or by Andrew Florko
Published on 2010-05-10T18:20:29Z
Indexed on
2010/05/10
18:24 UTC
Read the original article
Hit count: 204
Hello everybody,
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.
© Stack Overflow or respective owner