vishnu sharma

vishnu sharma

  • NA
  • 18
  • 846

Not showing data in the fields in edit view

Jul 21 2018 6:17 AM
public ActionResult Update(int id = 0)
{
EntryTable entrytable = db.EntryTables.Find(id);
if (entrytable != null)
{
entrytable = new EntryTable
{
City = new SelectList(db.Cities, "CityId", "CityName"),
Category = new SelectList(db.Categories, "CategoryID", "CategoryName")
};
}
return View(entrytable);
}
//
// POST: /Home/Update/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Update(EntryTable entrytable)
{
if (ModelState.IsValid)
{
entrytable.City = new SelectList(db.Cities, "CityId", "CityName");
entrytable.Category = new SelectList(db.Categories, "CategoryId", "CategoryName");
db.Entry(entrytable).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(entrytable);
}
 
 
 
 
//view
 
<div class="container" style="width:40%; margin-top:2%;float:right">
@Html.LabelFor(model => model.CityId)
@Html.DropDownListFor(model => model.CityId, Model.City, "--Select City--", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.CityId)
</div>
<div class="container" style="width:40%; margin-top:2%;float:left">
@Html.LabelFor(model => model.CategoryId)
@Html.DropDownListFor(model => model.CategoryId, Model.Category, "--Select Category--", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.CategoryId)
</div>
 

Answers (1)