Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I got error in MVC 3



@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)

Posted
Updated 2-Aug-14 0:18am
v2

1 solution

1.Your Model must have a type that implement IEnumerable or to be a list of items (like List, array, etc), and you must have declared in your view like in the next code:
HTML
@model List<MymodelUsedType>

or like:
@model MyModelType

2.You should change your @Html.DisplayFor with @Html.Display like in the next example:
HTML
@foreach(var item in Model)
{
   @Html.Display(item.CountryCode)
   @Html.Display(item.CountryName)
}
 
Share this answer
 
v2
Comments
Sai Prasad anumolu 3-Aug-14 2:39am    
I gave your code ... another is like this

public class _Page_Views_Home_DisplayTable_cshtml : System.Web.Mvc.WebViewPage<List<country>> {

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900