简体   繁体   English

没有表单标记的ASP.NET MVC3客户端验证

[英]ASP.NET MVC3 Client side validation without form tag

I have a view which contains some input fields. 我有一个包含一些输入字段的视图。 They are bound to a viewmodel. 它们绑定到视图模型。 They also have validation messages. 他们还有验证消息。 But the view doesn't have a form tag (neither Ajax.BeginForm nor Html.BeginForm). 但是视图没有表单标记(Ajax.BeginForm和Html.BeginForm)。

The user enters some input, selects (via checkboxes) some rows from a table and then clicks a button. 用户输入一些输入,从表中选择(通过复选框)某些行,然后单击按钮。 I have handled this button's click event on the client side and written an AJAX call to send data to server. 我已在客户端处理此按钮的单击事件,并编写了一个AJAX调用以将数据发送到服务器。 This works fine, except the client side validation. 这种方法很好,除了客户端验证。 Since I have no form tag, the client side validation is ignored. 由于我没有表单标记,因此忽略客户端验证。 Is there any way to validate user input and show error messages if necessary, without using form tag? 有没有办法验证用户输入并在必要时显示错误消息,而不使用表单标签?

No, the jquery validation plugin only works on forms contained by a form tag. 不,jquery验证插件仅适用于表单标记包含的表单。 There are two methods that you might call to validate you fields 您可以调用两种方法来验证字段

$('some_selector').validate()
$('some_selector').valid()

neither of these will work without a form tag 如果没有表单标签,这些都不会起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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