MVC - Posting Form To Different MVC Post Action Depending On The Clicked Submit Button - Stack Overflow
MVC - Posting Form To Different MVC Post Action Depending On The Clicked Submit Button - Stack Overflow
asp.net mvc - Posting form to different MVC post action depending on the clicked submit button - Stack Overflow
<div class="pageWrapperForSearchSubmit">
<input type="submit" class="submitButton"
value="Submit" id="btnSubmitChange" />
</div>
}
//ACTION
[HttpPost]
public ActionResult Submit(SearchCostPage searchModel, string Command)
{
SessionHelper.ProjectCase = searchModel.ProjectCaseNumber;
if (string.Equals(Command, Constants.SearchPage.ExportToExcel))
{
}
}
QUESTIONS
References:
https://stackoverflow.com/questions/21116999/posting-form-to-different-mvc-post-action-depending-on-the-clicked-submit-button 1/6
31/5/2019 asp.net mvc - Posting form to different MVC post action depending on the clicked submit button - Stack Overflow
asp.net-mvc asp.net-mvc-4
4 Answers
¿No encuentras la ✕
respuesta? Pregunta en
Stack Overflow en español.
Ofyou
By using our site, course, you can
acknowledge use
that youUrl
have read and understand our Cookie Policy, Privacy Policy, and our
Terms of Serviceextensions
. methods in your Razor to
specify the form action.
https://stackoverflow.com/questions/21116999/posting-form-to-different-mvc-post-action-depending-on-the-clicked-submit-button 2/6
31/5/2019 asp.net mvc - Posting form to different MVC post action depending on the clicked submit button - Stack Overflow
$(document).on('click', '[type="submi
var $this = $(this);
var formAction = $this.attr('data-f
$this.closest('form').attr('action'
});
BEST ANSWER 1:
ActionNameSelectorAttribute
20 mentioned in
http://weblogs.asp.net/scottgu/archiv
e/2007/12/09/asp-net-mvc-
framework-part-4-handling-form-edit-
and-post-scenarios.aspx
ANSWER 2
Second Approach
https://stackoverflow.com/questions/21116999/posting-form-to-different-mvc-post-action-depending-on-the-clicked-submit-button 4/6
31/5/2019 asp.net mvc - Posting form to different MVC post action depending on the clicked submit button - Stack Overflow
Side)
</button>
<a id="cancelUrl" href="@Html.Attribu
style="display:none;"></a>
<script type="text/javascript">
$(function() {
// this code detects a button
// in the form to be the `nam
$('form input[type=submit]').
var $form = $('form');
form.removeAttr('option')
form.attr('option', $(thi
});
// this code updates the URL
$("form").submit(function(e)
var option = $(this).attr
if (option) {
e.preventDefault();
var currentUrl = $(th
$(this).attr('action'
}
});
});
</script>
...
<input type="submit" ... />
<input type="submit" name="excel" ...
routes.MapRoute(
name: "ExcelExport",
url: "SearchDisplay/Submit/excel"
defaults: new
{
controller = "SearchDisplay",
action = "SubmitExcel",
});
You
By using our site, youcan setup 2 distinct
acknowledge that youactions
have read and understand our Cookie Policy, Privacy Policy, and our
Terms of Service.
https://stackoverflow.com/questions/21116999/posting-form-to-different-mvc-post-action-depending-on-the-clicked-submit-button 5/6
31/5/2019 asp.net mvc - Posting form to different MVC post action depending on the clicked submit button - Stack Overflow
[ActionName("SubmitExcel")]
public ActionResult Submit(SearchCost
{
...
}
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our
Terms of Service.
https://stackoverflow.com/questions/21116999/posting-form-to-different-mvc-post-action-depending-on-the-clicked-submit-button 6/6