Cannot find Html.Serialize helper in MVC 5 futures

二次信任 提交于 2019-11-27 06:32:36

问题


I just installed MVC 5 futures in my solution using Package Manager, but I cannot find this helper method Html.Serialize, which was there in previous MVC Futures releases.

My Question: What namespace I need to include to start using Html.Serialize helper method with MVC 5 Futures?


回答1:


Apparently, this extension helper is no longer included in the current MVC Futures.

In my case, I replaced the function call Html.Serialize by MvcSerializer.Serialize method which is included in Microsoft.Web.Mvc namespace.

To serialize any object in a hidden field:

@Html.Hidden("otherComplexData", new Microsoft.Web.Mvc.MvcSerializer().Serialize(complexObject))

Later, the controller can turn back the initial object:

[HttpPost]
public ActionResult Index(
    IndexViewModel model,
    [Deserialize] DataType otherComplexData
)

I hope you find it useful.



来源:https://stackoverflow.com/questions/25828553/cannot-find-html-serialize-helper-in-mvc-5-futures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!