Form in ASP.NET MVC (1.0) does not fire if “id” attribute is present (jQuery Validation requirement)
-
22-07-2019 - |
Question
<% Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "form_logon" }); %>
or
<form id = "form_logon", action="/Home/Index" method="post">
just don't work. Pressing a submit button if ID is present does nothing, while id is required for jQuery validation plugin.
Solution
Are you sure you don't have any javascript errors on your page? I use the first format pretty extensively with no problems, with and without the Validation plugin. Note that your second example has an extra comma, but I'm guessing that's a transcription error. I'd look to make sure that you don't have a javascript error that is halting all javascript on the page (though that wouldn't explain a plain, old submit button not working).
OTHER TIPS
I got similar issue and couldn't get any proper solution to this. However, since I only had one form in my MVC page, I reverted back to Html.BeginForm() without any parameters, and in the jQuery code, I just used the following:
$("form").validate(/* my rules and messages */);
instead of:
$("#userForm").validate(/* my rules and messages */);
Hope this helps.
Regards Naweed