Reputation: 85775
I am trying to stop my form from submitting yet I never can get it work and always end up changing it to a button type. However I want to see if I keep the submit button as is if I can have in my Asp.net mvc application as a FormCollection Paramater.
Yet I can't even try really passing in anything until I get it to stop submitting. I don't know why I can't get it work
View
$(function()
{
$("#Submit1").submit(function(e)
{
$.post("Page1", function(e)
{
alert("alert");
});
return false;
});
});
<% using (Html.BeginForm("Page1","Home",FormMethod.Post,new {@id = "mytest" }))
{ %>
<%= Html.TextBox("test","hi") %>
<input id="Submit1" type="submit" value="submit" />
<% } %>
Controller Method
public bool Page1()
{
return false;
}
Upvotes: 1
Views: 609
Reputation: 2233
You can always use preventDefault()
on the event:
$("#submit-btn").click(function(e){
e.preventDefault();
....
if (validations pass)
$("#theform").submit();
});
Upvotes: 0
Reputation: 38860
The submit() method should be attached to the form not the submit button. Like this:
$("#mytest").submit(function(e) ....
Upvotes: 0
Reputation: 37267
You need to put the submit on the form, not on the input node.
$("#mytest").submit(function(e) {
...
}
Upvotes: 3