Reputation: 196689
I have the following code in my view of an asp.net-mvc site:
<input type="hidden" id="test" name="riskIssues[0].Reason" value="<% = risk.Reason %>" />
The issue is that if there is a double quote inside the risk.Reason variable lets say the reason is a string that is something like:
We need them to "ask" us first
and then i try to read the value using jquery ($("#test").val(), i only get the text that is before the double quote (in the example above, i would get
We need them to
What is the correct way to encode this so I can read the whole string including the double quotes and everything after
Upvotes: 0
Views: 1259
Reputation: 6132
You could use HttpServerUtility.HtmlEncoding
or WebUtility.HtmlEncode
to html encode your data received in your view. As shown in the examples here (MSDN) & here (MSDN)
Your string would end up looking like this:
We need them to "ask" us first
We need them to "ask" us first
Also have a look here (dotnetperls)
Upvotes: 1