Error in View :
Model Is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace BorbaneApplication.Model
{
public class Country
{
public string CountryCode { get; set; }
public string CountryName { get; set; }
}
}
View is :
@using BorbaneApplication.Model;
@model BorbaneApplication.Model.Country;
@{
ViewBag.Title = "DisplayTable";
}
DisplayTable
| Country Code | Country Name | Operations |
|---|---|---|
@Html.DisplayFor(modelitem =>item.CountryCode) | @Html.DisplayFor(modelitem=>item.CountryName) |
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Pradeep ShetRank #595 · 4K reputationPosted Aug 2, 2014, 11:57 PM EDT
Error was because, you view is a strongly typed model of Country class but in view you are trying to iterate through the Model which is not a strongly typed list
So to solve this problem, use the strongly type model of list of country.
@model List
And from ActionMethod return the List as a model like
return View("viewname", listofcountryobject);
Sai Prasad Anumolu175 reputationPosted Aug 3, 2014, 6:22 AM EDT