I want o pass some JSON object in HTML response and eval it in client. I used fallowing code in server:
TagBuilder tag = new TagBuilder("script");
tag.Attributes.Add("Id", id);
tag.Attributes.Add("type", "text/html");
tag.SetInnerText(new JavaScriptSerializer().Serialize(content));
return MvcHtmlString.Create(tag.ToString());
and I try to eval it in client :
var p = eval("(" + pEl.html() + ")");
but it didn't work because of encoding so I have to decode it by this:
var p = eval("(" + pEl.html().replace(/"/g,"'") + ")");
but it seem unpleasant , i try to use <%=%> in place of <%:%> in server side, but its remained same. any idea to solve problem? there is any better way to passing JSON along HTML response. Thanks