Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best approach is to have separate actions handling the different button calls as explained in <a href="http://blog.ashmind.com/2010/03/15/multiple-submit-buttons-with-asp-net-mvc-final-solution/" rel="noreferrer">this article</a>.</p> <p>If you want to have one ugly action doing all the stuff then you could give your submit buttons names:</p> <pre><code>@using (Html.BeginForm()) { ... input fields for the model &lt;button type="submit" name="btn" value="verify"&gt;Verify data&lt;/button&gt; &lt;button type="submit" name="btn" value="save"&gt;Save data&lt;/button&gt;    &lt;button type="submit" name="btn" value="redirect"&gt;Redirect&lt;/button&gt; } </code></pre> <p>You don't need any hidden fields or javascript. And then in your controller action you would check for the value of the <code>btn</code> parameter (which obviously will be part of you view model):</p> <pre><code>[HttpPost] public ActionResult Foo(MyViewsModel model) { if (model.Btn == "verify") { // the Verify button was clicked } else if (model.Btn == "save") { // the Save button was clicked } else if (model.Btn == "redirect") { // the Redirect button was clicked } else { // ??? throw } ... } </code></pre> <p>Of course if you follow my advice and separate your actions (as outlined in the article):</p> <pre><code>@using (Html.BeginForm("Action", "Home")) { ... input fields for the model &lt;input type="submit" name="verify" value="Verify data" /&gt; &lt;input type="submit" name="save" value="Save data" /&gt; &lt;input type="submit" name="redirect" value="Redirect" /&gt; } </code></pre> <p>and then:</p> <pre><code>[HttpParamAction] [HttpPost] public ActionResult Verify(MyViewModel model) { ... } [HttpParamAction] [HttpPost] public ActionResult Save(MyViewModel model) { ... } [HttpParamAction] [HttpPost] public ActionResult Redirect(MyViewModel model) { ... } </code></pre> <p>which is a far cleaner code which doesn't violate the Single Responsibility Principle.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload