我有一个这样的视图模型:
public class weightdata
{
...some properties
public string weights;
}
然后,我在控制器中有:
weightdata details = new weightdata();
Dictionary<string,float> dict = new Dictionary<string,float>();
//do something to fill the dictionary with values
var ser = new System.Web.Script.Serialization.JavaScriptSerializer();
details.weights = ser.Serialize(dict);
return View(details);
然后在视图中:
<script type="text/javascript">
var dict = @{Html.Raw(new JavaScriptSerializer().Deserialize<Dictionary<string,float>>(Model.Weights));}
</script>
但是页面的渲染是: var dict = (它是空白的)
如何将这个值字典放入 javascript 可以使用的位置?