In razor, this is what I have:
<span data="@(new { prop1 = "prop1val", prop2 = 5 })" id="span1"></span>
And, in JS, I want to parse that data attr val into a JSON object.
var dataObj = JSON.parse($("#span1").attr("data"));
alert(dataObj.prop1); // should alert "prop1val"
The way the razor is rendering is like this:
<span data="{ prop1 = prop1val, prop2 = 5 }" id="span1"></span>
Do I need to do something like @(new {...}).toJsonString() ? Is there something within razor I can just use?
Thanks!