Created
October 9, 2012 15:34
-
-
Save codereflection/3859562 to your computer and use it in GitHub Desktop.
Using ModelState.AddModelError for exception reporting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public ActionResult Edit(DonorViewModel model) | |
{ | |
try | |
{ | |
var donor = db.Donors.Get(model.Donor_ID); | |
model.CreatedOn = donor.CreatedOn; | |
model.DonorType_ID = donor.DonorType_ID; | |
model.ModifiedOn = DateTime.Now; | |
SetupEditViewData(model); | |
db.Donors.Update(model); | |
return RedirectToAction("Index"); | |
} | |
catch (Exception ex) | |
{ | |
ModelState.AddModelError(string.Empty, ex.Message); | |
return View(model); | |
} | |
} |
Thanks for the response. :) I think I'll probably go with your first suggestion. The trouble is this is not an internal app, but rather used by PTA parents who can have the entire spectrum of computer knowledge.
Oh, In that case, you should just have the ValidationSummary display your cell number and email address. :P
Well, two questions:
-
What do you expect the users to do with the Model Error?
-
Do you still display the model even if there are errors?
The only thing the users can do is report the error.
I would still display the model values on error.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I see your point. Would any of these work?
Or, you could just leave it as "good enough." If it's an internal app and your users will get the point, then I don't see anything wrong with it in this case.