The model item passed into the dictionary is of type 'System.Collections.Generic.List`1', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`

I am trying to run this code in MVC


public ActionResult TeleList()
List<TeleInfo> lstTeleInfo = new List<TeleInfo>();
oyetriviadbEntities db = new oyetriviadbEntities();
lstTeleInfo = db.TeleInfoes.ToList();
return View(lstTeleInfo);


.csthml(Razor View Code)

@model IEnumerable<MvcApplication3.Models.MTeleInfo>

ViewBag.Title = "TeleList";


@Html.ActionLink("Create New", "Create")
@Html.DisplayNameFor(model => model.TeleName)
@Html.DisplayNameFor(model => model.TeleMob)

@foreach (var item in Model) {
@Html.DisplayFor(modelItem => item.TeleName)
@Html.DisplayFor(modelItem => item.TeleMob)
@Html.ActionLink("Edit", "Edit", new { id=item.TeleGUID }) |
@Html.ActionLink("Details", "Details", new { id=item.TeleGUID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.TeleGUID })


Running above code in MVC I am getting the error as below

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[MvcApplication3.TeleInfo]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MvcApplication3.Models.MTeleInfo]

 Let me know what is the issue and how to resolve it?

Asked by:- Aiswarjya
: 8133 At:- 9/8/2017 7:35:52 AM
MVC Razor sql-server C#

3 Answers
profileImage Answered by:- neena

 You are passing the wrong Model if you check the line in controller it is

List<TeleInfo> lstTeleInfo = new List<TeleInfo>();

here in the above code, your model is TeleInfo, while in the View if you will check

@model IEnumerable<MvcApplication3.Models.MTeleInfo>

Your's razor is expecting List of type MTeleInfo, so you need to refer the correct Model name.

In the view, it should be

@model IEnumerable<MvcApplication3.TeleInfo>

Change the namespace/model-name according to what it is in your Project.

At:- 9/8/2017 8:12:36 AM Updated at:- 9/8/2017 8:24:12 AM
Yes, looking at the error, I think your answer is correct, @Aiswarjya let us know if this helped you by commenting here 0
By : vikas_jk - at :- 9/8/2017 8:17:56 AM
thanks, it worked, after changing namespace name to MvcApplication3.TeleInfo 0
By : Aiswarjya - at :- 9/8/2017 10:06:54 AM

profileImage Answered by:- vikas_jk

Your issue is in view, not in C# controller, you need to change the first line of your view, it should be something like 

@model IEnumerable<NameSpace.Modelname>

Your model name is not matching with the C# list you are passing to View

At:- 9/8/2017 8:29:20 AM

profileImage Answered by:- Aiswarjya

existing first line of View is 

@model IEnumerable<MvcApplication3.Models.MTeleInfo>

i changed it 

@model IEnumerable<MvcApplication3.MTeleInfo>

also got error

what is the namespace i will take

At:- 9/8/2017 8:33:42 AM Updated at:- 9/8/2017 8:54:52 AM
read @neena's answer, carefully, you need to replace model, and pass the same model to view, as you are using in C# controller 0
By : vikas_jk - at :- 9/8/2017 9:51:58 AM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use