0

In the following HTML + C# line:

<button type="button" onclick="Update(this, @Model.Quantity, '@Html.Raw(HttpUtility.JavaScriptStringEncode(order.Notes))')">Click Me<button>

the HttpUtility.JavaScriptStringEncode does not encode double quotes which breaks the function call. So, I have add .Replace("\"","&quot;") to it:

@Html.Raw(HttpUtility.JavaScriptStringEncode(order.Notes).Replace("\"","&quot;"))

This works but why wouldn't the utility encode a double quote? Am I using it incorrectly or is it simply created that way?

Lukas
  • 1,699
  • 1
  • 16
  • 49
  • 1
    Why use Html.Raw? – NineBerry Feb 28 '20 at 14:43
  • Thanks for the response. I don't know. I copied some code from [here](https://stackoverflow.com/questions/5225796/javascript-razor-and-escape-characters-like-apostrophe) without understanding its structure and tried to use it. Removing `Html.Raw` seems to have made the utility properly escape the `"` character. I'll look into this more. – Lukas Feb 28 '20 at 15:03

0 Answers0