How can one access model’s validation message through ModelState variable at the controller?
How can one access model’s validation message through ModelState variable at the controller?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Of course checks must be done as each of those accessors could simply return null. But if you are absolutely sure that
SomePropertyhas at least one error message in modelstate it’s OK.Those checks could of course be encapsulated in an extension method so that in your controller you could simply:
Like this for example: