error : The model item passed into the dictionary is of type In MVC

Last Reply 3 days ago By dharmendr

Posted 3 days 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>
            <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

 

You are viewing reply posted by: dharmendr 3 days ago.