In the Edit action in ASP.NET MVC, certain fields can be hidden from the user using HiddenFieldFor. However, this does not protect the fields (such as ID, data creation date) from editing.
For example, the Student model has Id, Name, and Birthday fields. I like to let users update the name, but not the id and birthday.
For an editing action like this
public ActionResult Edit(Student student)
{
if (ModelState.IsValid)
{
db.Entry(student).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(student);
}
How can I disable editing Id and Birthday? Thank!
Jim source
share