Cannot find Html.Serialize helper in MVC 5 futures

后端 未结 1 1677
轮回少年
轮回少年 2020-12-10 20:06

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 previo

相关标签:
1条回答
  • 2020-12-10 20:31

    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.

    0 讨论(0)
提交回复
热议问题