表达式可能不包含动态操作? [英] an expression may not contain a dynamic operation?
本文介绍了表达式可能不包含动态操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在MVC 3中遇到错误
I got error in MVC 3
@foreach(var item in型号)
{
}
国家代码 | 国家名称 | 操作 |
---|---|---|
@ Html.DisplayFor(modelitem => item.CountryCode)错误是 表达式可能不包含动态操作 | @ Html.DisplayFor(modelitem => item.CountryName) |
@foreach (var item in Model)
{
}
Country Code | Country Name | Operations |
---|---|---|
@Html.DisplayFor(modelitem =>item.CountryCode) Error is an expression may not contain a dynamic operation | @Html.DisplayFor(modelitem=>item.CountryName) |
推荐答案
1.YourModel
必须有一个实现IEnumerable
的类型,或者是一个项目列表(如List,array等),你必须拥有在您的视图中声明,如下一个代码:
1.YourModel
must have a type that implementIEnumerable
or to be a list of items (like List, array, etc), and you must have declared in your view like in the next code:
@model List<MymodelUsedType>
或类似:
or like:
@model MyModelType
2.你应该改变您的 @ Html.DisplayFor
与 @ Html.Display
,如下例所示:
2.You should change your @Html.DisplayFor
with @Html.Display
like in the next example:
@foreach(var item in Model)
{
@Html.Display(item.CountryCode)
@Html.Display(item.CountryName)
}
这篇关于表达式可能不包含动态操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文