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 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Pradeep ShetPosted Aug 3, 2014, 3:57 AM
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 AnumoluPosted Aug 3, 2014, 10:22 AM