Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Validation: result in a javascript property?

I'm using ASP.NET MVC Validation. I want to know in my javascript functions whether the validation has error.

Is there any builtin javascript property integrated with ASP.NET MVC Framework to get this information?

like image 454
Ricibald Avatar asked Nov 23 '25 22:11

Ricibald


1 Answers

Built-in ASP.NET MVC validation is server-side only so there is no standard variable like Page_IsValid from ASP.NET.

If you want to add client-side validation you could use xVal or jQuery Validation Plugin

Some articles on xVal:

  • xVal - a validation framework for ASP.NET MVC
  • Client-side form validation made easy

As an option you could validate data on a server and render this JavaScript code in a view:

<script type="text/javascript">
    var Page_IsValid = <%= ViewData.ModelState.IsValid %>;
</script> 
like image 60
Alexander Prokofyev Avatar answered Nov 26 '25 11:11

Alexander Prokofyev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!