ASP.Net MVC Error: The model item passed into the dictionary is of type

Last Reply 2 months ago By dharmendr

Posted 2 months ago

hi I used ViewModel in MVC project below are codes

    @using WebApplication9.Models
    @model  WebApplication9.ViewModel.ListViewModel

    @foreach (var item in Model.Students)
    {
        <tr>
            <td>@item.Name</td>
            <td>@item.Family</td>
            <td>@item.CodeMelli</td>
            <td>@item.Age</td>
            <td>@item.BirthDate.Value.ToPersian()</td>
            <td>@item.Email</td>

HomeController

        using WebApplication9.ViewModels;
        public ActionResult List()
        {
            ListViewModel vm = new ListViewModel();
            vm.Students = bl.Select();
            vm.Lessons = blLesson.Select();
            return View(vm);
        }

ListViewModel.CS:

namespace WebApplication9.ViewModels
{
    public class ListViewModel
    {
        public List<Student> Students { get; set; }
        public List<Lesson> Lessons { get; set; }
    }
}

but when run page below error accure:

The model item passed into the dictionary is of type 'WebApplication9.Controllers.ListViewModel', but this dictionary requires a model item of type 'WebApplication9.ViewModels.ListViewModel'.

Best Regards

Neda