I have a controller
public ActionResult controller(){ Viewclass view = new Viewclass(); ... return PartialView("Tab", view); }
In which the view class is something like, the string A and B is my compiled JSON string.
public class ViewClass {public string A {get;set;} public string B {get;set;} }
In the Partial view, I want to do
<script type=开发者_如何学C"text/javascript">
RunMap( @Model.A, @Model.B);
</script>
The problem is the " is parsed as ", like {"City":} into the function. How can I fix this?
Use @Html.Raw
to treat the string as raw HTML (e.g MVC will not encode it)
<script type="text/javascript">
RunMap(@Html.Raw(Model.A), @Html.Raw(Model.B));
</script>
Of course, you need to make sure that the input (e.g the data) it handled carefully.
This should work: RunMap( "@Model.A", "@Model.B");
If you want to pass them as JSON objects, then take out the quotes.
精彩评论