c# - MVC Error Message -


I'm using the code first and taking the automatically generated visual model. I have a unique column set

< P> However when it reaches DB. SaveChanges (); Due to duplicate in the database, I get an error.

  Create Public Actions ([Bind (Include (= "Columns") TV ({ModelState.IsValid) {db .Tv.Add (TV); Db.SaveChanges (); Return Redirect Action ("Index"); } See Return (TV); }  

How can I create an error message and send the user back to the last page that displays that error? I have tried to catch a try, but it did not work

I can also use an effort / gesture to save the value of the savings method.

  Create public actions ([bind (= "include column")] TV TV) {if (ModelState.IsValid) {try {db.Tv. Add (TV); Int num = db.SaveChanges (); If (num == 0) {// prompt user} return redirection tie ("index"); Hold (Optical Concepts Exception) {// Handle Exception}} Return View (TV); }  

Comments