javascriptasp.net-mvcserver-variablesserver-tags

Accessing Server Tags inside Javascript in MVC project


I'd like to use some server tags inside a Javascript function:

<%=Model.HtmlProperty%>

In the past I have stored this value in a hidden input field, but when a property contains HTML you get problems with special characters such as quotes. I would like to avoid having to encode and decode in the controller to avoid problems with special characters.

Rick Strahl has a couple posts on this problem in a web forms project, but I'm looking for an elegant solution for an MVC project.

UPDATE: Robert Harvey's answer below suggests to encode the html. Again, that isn't what I want to do. Ultimately, I'm trying to inject html script into an fckeditor instance. This must be done in javascript. I'm trying to figure out how to access the value of <%=Model.HtmlProperty%> inside javascript without storing encoded text in a hidden input element.


Solution

  • It seems that what I was hoping to do - using server tags inside javascript - is not possible. I had been storing the string inside a hidden input element, and as per queen3's comment, it seems that I will have to keep on doing what I have been doing all along. Thanks everyone for your input.