I'm using ASP.NET MVC Validation. I want to know in my javascript functions whether the validation has error.
我正在使用ASP.NET MVC验证。我想在我的javascript函数中知道验证是否有错误。
Is there any builtin javascript property integrated with ASP.NET MVC Framework to get this information?
是否有与ASP.NET MVC Framework集成的内置javascript属性来获取此信息?
1 个解决方案
#1
Built-in ASP.NET MVC validation is server-side only so there is no standard variable like Page_IsValid from ASP.NET.
内置的ASP.NET MVC验证仅在服务器端,因此没有像ASP.NET的Page_IsValid这样的标准变量。
If you want to add client-side validation you could use xVal or jQuery Validation Plugin
如果要添加客户端验证,可以使用xVal或jQuery Validation Plugin
Some articles on xVal:
关于xVal的一些文章:
- xVal - a validation framework for ASP.NET MVC
- Client-side form validation made easy
xVal - ASP.NET MVC的验证框架
客户端表单验证变得简单
As an option you could validate data on a server and render this JavaScript code in a view:
作为选项,您可以验证服务器上的数据并在视图中呈现此JavaScript代码:
<script type="text/javascript">
var Page_IsValid = <%= ViewData.ModelState.IsValid %>;
</script>
#1
Built-in ASP.NET MVC validation is server-side only so there is no standard variable like Page_IsValid from ASP.NET.
内置的ASP.NET MVC验证仅在服务器端,因此没有像ASP.NET的Page_IsValid这样的标准变量。
If you want to add client-side validation you could use xVal or jQuery Validation Plugin
如果要添加客户端验证,可以使用xVal或jQuery Validation Plugin
Some articles on xVal:
关于xVal的一些文章:
- xVal - a validation framework for ASP.NET MVC
- Client-side form validation made easy
xVal - ASP.NET MVC的验证框架
客户端表单验证变得简单
As an option you could validate data on a server and render this JavaScript code in a view:
作为选项,您可以验证服务器上的数据并在视图中呈现此JavaScript代码:
<script type="text/javascript">
var Page_IsValid = <%= ViewData.ModelState.IsValid %>;
</script>