I cannot understand why I have this error because what I'm trying to do should be fairly simple:
The model item passed into the dictionary is of type 'WebApplication1.Models.Location', but this dictionary requires a model item of type 'System.Collections.Generic.List`1[WebApplication1.Models.Location]'.
View code Location_List.cshtml
@model List<WebApplication1.Models.Location>
@{
Layout = "~/Views/Shared/_LayoutAdminPanel.cshtml";
}
<div class="table-responsive">
<table class="table">
<thead class="thead-inverse">
<tr>
<th>Location ID</th>
<th>Location Name</th>
<th>Photo Path</th>
<th>Details</th>
<th>City ID</th>
<th>Modify</th>
</tr>
</thead>
<tbody>
@for (int i = 0; i < Model.Count; i++)
{
<tr>
<th scope="row">Location00_@Model[i].LocationID</th>
<td>@Model[i].LocationName</td>
<td>@Model[i].PhotoPath</td>
<td>@Model[i].Details</td>
<td>@Model[i].CityID</td>
<td><a href="/Admin/Location_Edit?ID=@i">Edit</a></td>
</tr>
}
Controller Code AdminController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication1.Models;
namespace MySafar.Controllers
{
public class AdminController : Controller
{
public ActionResult Location_New()
{
return View();
}
[HttpPost]
public ActionResult Location_List()
{
Location l = new Location();
l.LocationID = Convert.ToInt32(Request.Form["LocationID"]);
l.LocationName = Request.Form["LocationName"];
l.PhotoPath = Request.Form["PhotoPath"];
l.Details = Request.Form["Details"];
l.CityID = Convert.ToInt32(Request.Form["CityID"]);
if (Session["Location"]==null)
{
Session["Location"] = new List<Location>();
}
List<Location> loc = (List<Location>)Session["Location"];
loc.Add(l);
return View("Location_List", l);
}
}
I was check whole code 4-5 times i cannot understand where is the actual problem... any solution? please....