欢迎各位兄弟 发布技术文章
这里的技术是共享的
1) In mvc3 with razor @Html.Raw(Json.Encode(object)) seems to do the trick.
@Html.RenderAsJson(Model) helper.Raw(Json.Encode(model));
2) JsonConvert.SerializeObject(Model对象);
3) SomeModelView returnData = someDataMapper.getbyid(1);
var serializer = new JavaScriptSerializer();
ViewData["JSON"] = serializer.Serialize(returnData);
return View(myview, returnData);
//create base js object;
var myWidget= new Widget(); //Widget is a class with a public member variable called data.
myWidget.data= <%= ViewData["JSON"] %>;