You can do that, but you will need to write some JavaScript to handle this. Simply adding a new <intput type="submit"> element and changing it's value attribute won't help because it will POST the form to the same action method. If you do use this approach,
you will also need to ensure that the action methods are distinct so that you don't get an error indicating that an ambiguous action method was found.
You could try something like the following (Let's assume this is in Index.aspx)
jeloff
Contributor
2493 Points
432 Posts
Microsoft
Re: submit Button In Mvc
Apr 27, 2009 05:28 PM|LINK
Hi
You can do that, but you will need to write some JavaScript to handle this. Simply adding a new <intput type="submit"> element and changing it's value attribute won't help because it will POST the form to the same action method. If you do use this approach, you will also need to ensure that the action methods are distinct so that you don't get an error indicating that an ambiguous action method was found.
You could try something like the following (Let's assume this is in Index.aspx)
<% using(Html.BeginForm("Submit", "Home")) { %>
<% =Html.TextBox("foo") %>
<% =Html.TextBox("bar") %>
<input type="submit" value="submit 1">
<intput type="submit" value="submit 2" onclick="submit2()">
<% } %>
In your controller you will need to different action methods, for example
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Submit(string foo) {
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AnotherSubmission(string foo, string bar) {
}
The 2nd submit button's onclick function using jQuery:
function submit2() {
$.post("/Home/AnotherSubmission", { foo: $("#foo").val(), bar: $("#bar").val() });
}
Jacques