1
votes

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="text/javascript">
RunMap( @Model.A, @Model.B);
</script>

The problem is the " is parsed as &quot, like {&quotCity&quot:} into the function. How can I fix this?

2

2 Answers

3
votes

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.

1
votes

This should work: RunMap( "@Model.A", "@Model.B");

If you want to pass them as JSON objects, then take out the quotes.