简体   繁体   中英

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?

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:

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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM