I need to do a check if my model is valid from inside my Razor view. If it’s valid then I want to be able to show some HTML.
How can I do this. I want something like
@if ( Model.IsValid ) {
}
but the above does not work
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.
You can check whether or not the ModelState is valid, but keep in mind that you’re only checking the validity of the ModelState at the time the web request was made:
Additionally, you can check validatity of a property on the model in the view: