在 MVC 5 期货中找不到 Html.Serialize 助手 [英] Cannot find Html.Serialize helper in MVC 5 futures
问题描述
我刚刚使用包管理器在我的解决方案中安装了 MVC 5 futures,但我找不到这个辅助方法 Html.Serialize,它在以前的 MVC 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.
我的问题:我需要包含什么命名空间才能开始在 MVC 5 Futures 中使用 Html.Serialize 辅助方法?
My Question: What namespace I need to include to start using Html.Serialize helper method with MVC 5 Futures?
推荐答案
显然,这个扩展助手不再包含在当前的 MVC Futures 中.
Apparently, this extension helper is no longer included in the current MVC Futures.
就我而言,我将函数调用 Html.Serialize 替换为 MvcSerializer.Serialize 方法,包含在 Microsoft.Web.Mvc 命名空间中.
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
)
希望你觉得它有用.
这篇关于在 MVC 5 期货中找不到 Html.Serialize 助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!