nom*_*mad 4 c# asp.net-mvc razor asp.net-mvc-4
为什么我无法在下面的代码中使用强类型助手?
@using ISApplication.Models
@model IEnumerable<PersonInformation>
@foreach (PersonInformation item in Model)
{
@Html.LabelFor(model => model.Name) // Error here.
@item.Name // But this line is ok
@* and so on... *@
}
Run Code Online (Sandbox Code Playgroud)
错误消息是
The type of arguments for method '...LabelFor<>... ' cannot be inferred from the usage. Try specifying the type arguments explicitly.
有任何想法吗?谢谢.
试试这种方式.您需要从项目中访问名称.
@foreach (PersonInformation item in Model)
{
@Html.LabelFor(x => item.Name);
@Html.DisplayFor(x =>item.Name)
}
Run Code Online (Sandbox Code Playgroud)