Delete Method based on condition in MVC 4

fady88

New Member
I have created an application in MVC 4 using Razor HTML. I have set up a model that has a few properties and my delete method which is posted below. This method works perfectly except for the fact that I don't want it to allow me to delete anything if one of the properties is not a certain number. How can i implement that in this method? \[code\]public ActionResult Delete(int id = 0){Material material = db.Materials.Find(id);if(material == null){ return HttpNotFound();}return View(material);}[HttpPost, ActionName("Delete")]public ActionResult DeleteConfirmed(int id){Material material = db.Materials.Find(id);db.Materials.Remove(material);db.SaveChanges();return RedirecttoAction("Index");}\[/code\]
 
Back
Top