使用asp.net MVC的 HtmlHelper 时遇到的小问题,报错:Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

异常信息:Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions

解决办法:


由以下代码:
@foreach (var item in Model)
{
    @Html.DisplayFor(m => !item.IsIdle, "BoolIcon")
}
改为: @foreach (var item in Model) { var active = !item.IsIdle; @Html.DisplayFor(m => active , "BoolIcon") }

 或者

由以下代码:

<div class="controls" style="width:20%">
@{ int index = @Model.chapter_index + 1;}
@Html.TextBoxFor(model => index, new { @class = "span11" })
</div>

改为:

<div class="controls" style="width:20%">
@{ int index = @Model.chapter_index + 1;}
@Html.TextBoxFor(model => index, new { @class = "span11" })
</div>

 

posted @ 2019-01-16 16:43  向萧  阅读(1161)  评论(1编辑  收藏  举报