And this is the class I'm using. I used the db first approach.
public partial class Ingredient
{
public int id { get; set; }
public string name { get; set; }
public string desc{ get; set; }
public byte is_deleted { get; set; }
public int Ingredient_Type_id { get; set; }
public int UOM_id { get; set; }
}
I have this code, the scaffolded one that updates a record.
public ActionResult EditDetails(Ingredient ingredient)
{
if (ModelState.IsValid)
{
db.Entry(ingredient).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.UOM_id = new SelectList(db.Unit_Of_Measurement, "id", "name", ingredient.UOM_id);
ViewBag.Ingredient_Type_id = new SelectList(db.Ingredient_Type, "id", "name", ingredient.Ingredient_Type_id);
return View(ingredient);
}
From what I see and understand in the code above, it updates all the fields in the record. However, I want to only update the name
and desc
fields. How should I do this? I'm also new in doing this, so an explanation will be appreciated too. Thank you.