Harsh Jani

Harsh Jani

  • NA
  • 34
  • 52k

I want to solve the given error

Apr 15 2015 4:08 AM
Hi!

I am getting the following error. Can anyone help me solve this error? The code is: -

public class CategoryController : Controller
{
//
// GET: /Category/
ProductsDbEntities ctx;

public CategoryController()
{
ctx = new ProductsDbEntities();
}

public ActionResult Index()
{
try
{
var categoryList = ctx.Categories.ToList();
return View(categoryList);
}

catch (Exception ex)
{
throw ex;
}
}

The code for the View is: -

@model MvcSession.Models.CategoryDetails

@{
ViewBag.Title = "SearchProducts";
}


@using (Html.BeginForm())
{
@Html.EditorFor(cat => cat.CategoryId);


<input type="submit" value="Search" class="btn btn-default" />
}

I am getting the following error when I run the application :-

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[MvcSession.EntityModel.Category]', but this dictionary requires a model item of type 'MvcSession.Models.CategoryDetails'.

Answers (2)