1

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I hope asp.net mvc "Html" object will get methods for javascript/html attributes/json safe encoding in the closest future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.