简体   繁体   中英

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).

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. 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. 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

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