I have the following Action method.
public ActionResult Action()
{
var model = new SampleViewModel();
model.JsonString = ReadJsonStringFromSomewhere();
return ViewResult(model);
}
In my view I have the following method to initialize a javascript variable.
<script type="text/javascript">
var jsObject = eval("(" + <%= Model.JsonString %> + ")");
alert(jsObject);
</script>
The 'jsObject' I get is undefined. What is wrong here. Also is it the best method to initialize a javascript variable with a complex json string?