I am new to MVC frame work. And i am making one page where we can see details of department by clicking on details link button.
While User click link button it fetch the all the records of the particular department in List Collection and redirect to Details View.Data has been fetched in List but while going to Details view it Generates following error:
The model item passed into the dictionary is of type ‘System.Collections.Generic.List1[DocPageSys.Models.Interfaces.DepartmentInfo]', but this dictionary requires a model item of type 'DocPageSys.Models.Interfaces.DepartmentInfo`’.
I understood the error but confusion to solve it.And stuck with this problem…
Since your
Detailsview is strongly typed toDepartmentInfo:you need to pass a single instance of it from the controller action instead of a list:
So make sure that when you are calling the
return View()method from your controller action you are passing a singleDepartmentInfoinstance that you have fetched from your data store.To make it run fine initially you could simply hardcode some value in it:
Oh, and you will notice that I didn’t use any ViewData/ViewBag. You don’t need it. Due to their weakly typed nature it makes things look really ugly. I would recommend you to always use view models.