3
votes

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?

1
why are you ignoring form tag? - Thulasiram
@deniz I am getting same problem , do you find any other way to resolve this issue? - nirav
i couldn't avoid using form tag. but i placed a hidden input into my form and bound it to a field in my viewmodel (via @Html.HiddenFor helper method). every time user selects a row from the table, selected id is appended to this hidden field. so, when user clicks submit button, my viewmodel is passed to the controller, including the hidden field which contains selected ids as comma separated string (e.g "3,5,8,9"). then i parsed this string on the server side and performed necessary operations. the validation is also performed since i have used form tag. hope it helps. - Deniz Alpaslan

1 Answers

4
votes

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