I create a partial view and add this in "Create.chtml" in my project which will display all area from database in create page. Everything(Insert, Update,Delete) works fine but when i click on the create button without select an item from dropdownlist it generate an error.
The model item passed into the dictionary is of type 'NHPractice2.Models.Area', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[NHPractice2.Models.Area]'.
Partial View
@model IEnumerable<NHPractice2.Models.Area>
@using NHPractice2.Models
@{
WebGrid grdArea = new WebGrid(Model, canPage: true, rowsPerPage: 10, defaultSort: "Name");
}
@grdArea.GetHtml(tableStyle: "Grid", headerStyle: "Header", alternatingRowStyle: "altRow", columns: grdArea.Columns(
grdArea.Column("Sl No.", format: item => item.WebGrid.Rows.IndexOf(item) + 1, style: "serialCol"),
grdArea.Column("Area", format: item => item.Name),
grdArea.Column("City", format: item => item.CityName),
grdArea.Column("Action", format: @<text>@Html.ActionLink("Edit", "Edit", new { id = item.ID }, new { onclick = "return confirm('Are sure wants to edit?');" }) | @Html.ActionLink("Delete", "Delete", new { id = item.ID }, new { onclick = "return confirm('Are sure wants to delete?');" })</text>)
)
)
Controller Code
[ChildActionOnly]
public ActionResult AreaList()
{
IEnumerable<Area> areas = AreaRepo.ShowAreaList(1, 0, "", 0);
return PartialView("AreaList",areas);
}
Code from Create.chtml
@Html.Action("AreaList", new List<NHPractice2.Models.Area> { new NHPractice2.Models.Area() });
What I have tried:
I tried several times to solve it but same result.