How can I check if my model is valid from inside the razor view?

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:

@if (ViewData.ModelState.IsValid) {
    ...
}

Additionally, you can check validatity of a property on the model in the view:

@if (ViewData.ModelState.IsValidField("FIELD_NAME")) {
    ...
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)