欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

How to convert View Model into JSON object in ASP.NET MVC? 对象转 json 字符串 有大用 有大大用

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"] %>;


来自   https://stackoverflow.com/questions/3365551/how-to-convert-view-model-into-json-object-in-asp-net-mvc


普通分类: