Guest User

Untitled

a guest
Aug 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. MVC ModelError how to get value
  2. ModelState.AddModelError("duplicateInvoiceNumberOrganisation", "The combination of organisation and invoice number must be unique");
  3.  
  4. controller.ModelState.Values
  5.  
  6. Count = 1
  7. [0]: {System.Web.Mvc.ModelState}
  8.  
  9. string error = ModelState["duplicateInvoiceNumberOrganisation"]
  10. .Errors[0]
  11. .ErrorMessage;
  12.  
  13. string error = ModelState
  14. .Where(x => x.Value.Errors.Count > 0)
  15. .First()
  16. .Value
  17. .Errors[0]
  18. .ErrorMessage;
Add Comment
Please, Sign In to add comment