Hi
I may be repeating this question . I have a Class. I am able to log error in Database but how to return Error message to Controller & display at Client side.
public Add(Location objLoc) { try { using (SqlConnection con = new SqlConnection(Common.Con)) { con.Open(); SqlCommand cmd = new SqlCommand("sp_Location", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Id", objLoc.Id); cmd.Parameters.AddWithValue("@Description", objLoc.Description); cmd.Parameters.AddWithValue("@IsActive", true); i = cmd.ExecuteNonQuery(); } } catch (Exception ex) { ExceptionLogging.SendExcepToDB(ex); } }
************* Controller
public ActionResult CreateEdit(Location objLocation , string hfAU , string hfId) { if (ModelState.IsValid) { dbLocation.Add(objLocation); TempData["Message"] = "Successfully Saved."; ModelState.Clear(); } else { var query = from state in ModelState.Values from error in state.Errors select error.ErrorMessage; var errors = query.ToArray(); TempData["Message"] = "Error Encountered."; } }
Thanks