【发布时间】:2012-09-13 15:00:10
【问题描述】:
我有强类型列表视图
我有自定义的 html 助手,它必须得到 IEnumerable<object>
是否可以将我的模型(@model IEnumerable<MvcApplication2.Models.UserViewModel>)传递给我的 html 助手?
【问题讨论】:
标签: asp.net asp.net-mvc razor html-helper
我有强类型列表视图
我有自定义的 html 助手,它必须得到 IEnumerable<object>
是否可以将我的模型(@model IEnumerable<MvcApplication2.Models.UserViewModel>)传递给我的 html 助手?
【问题讨论】:
标签: asp.net asp.net-mvc razor html-helper
如果你的助手是这样定义的:
public static IHtmlString SomeHelper(this HtmlHelper<IEnumerable<object>> html)
那么不可能这样称呼它:
@model IEnumerable<MvcApplication2.Models.UserViewModel>
@Html.SomeHelper()
另一方面,如果它是这样定义的:
public static IHtmlString SomeHelper(this HtmlHelper html, IEnumerable<object> model)
您可以从视图中调用它并传递模型:
@model IEnumerable<MvcApplication2.Models.UserViewModel>
@Html.SomeHelper(Model)
【讨论】:
using 指令将定义此类的命名空间带入视图的范围。