Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Following Is my Error while i Edit, Update the record...

"The model item passed into the dictionary is of type 'IkkosAdminPortalWebSite.RecordDetail', but this dictionary requires a model item of type 'IkkosAdminPortalWebSite.Models.RecordDetails'."

In this RecordDetails---ModelClass, RecordDetail---Class in .edmx--.edmx.tt


Following is my code..

[HttpGet]
public ActionResult Edit(string actor= null)
{
RecordDetails record = objList.RecordDetails.Find(actor) as RecordDetails;
//var record = objList.RecordDetails.Find(actor);
if (record == null)
{
return HttpNotFound();
}
return View(record);
// return View();
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(RecordDetails EditRecord)
{

if (ModelState.IsValid)
{
objList.Entry(EditRecord).State = System.Data.EntityState.Modified;
objList.SaveChanges();
return RedirectToAction("RecordDetails");
}

return View(EditRecord);
}
Posted
Comments
baswaraj.s 21-Aug-14 8:44am    
IT SHOWING SAME ERROR IN Edit(string actor= null) Method in above code.

1 solution

You should return the type IkkosAdminPortalWebSite.Models.RecordDetails because the view is expecting model @model IkkosAdminPortalWebSite.Models.RecordDetails but you are returning the type IkkosAdminPortalWebSite.RecordDetail in the edit controller. So before you return the type set all the properties values of IkkosAdminPortalWebSite.RecordDetail to IkkosAdminPortalWebSite.Models.RecordDetails like below

C#
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(RecordDetails EditRecord)
{

if (ModelState.IsValid)
{
objList.Entry(EditRecord).State = System.Data.EntityState.Modified;
objList.SaveChanges();
return RedirectToAction("RecordDetails");
}
//Change you code little bit like below
 var viewModel=new  IkkosAdminPortalWebSite.Models.RecordDetails();
view.Property1=EditRecord.Property1;
//set all the properties you want
return View(viewModel);
}


Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900