Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find Html.Serialize helper in MVC 5 futures

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?

like image 421
Sunil Avatar asked Feb 13 '23 01:02

Sunil


1 Answers

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.

like image 188
joaghix Avatar answered Mar 06 '23 02:03

joaghix