Give your buttons the same name:
<button type="submit" name="btn" value="save_new" id="SaveNew">Save&New</button>
<button type="submit" name="btn" value="save_close" id="SaveClose">Save&Close</button>
and then your controller action could take this btn
string parameter.
[HttpPost]
public ActionResult Company(MyProject.Models.Company company, string btn)
{
if (btn == "save_new")
{
// the form was submitted using the Save&New button
}
else if (btn == "save_close")
{
// the form was submitted using the Save&Close button
}
else
{
// the form was submitted using javascript or the user simply
// pressed the Enter key while being inside some of the input fields
}
return View();
}
Also notice that I have used submit
buttons (type="submit"
) whereas in your example you have used simple buttons (type="button"
) which do not allow for submitting an html form.