Form with two destinations

Asked

Viewed 81 times

2

I have the following form:

@using (Ajax.BeginForm("minhaAction", "meuController", new AjaxOptions()
    {
        HttpMethod = "POST",
        OnFailure = "alert('Erro!')",
        OnSuccess = "TrabalharResultado"

    }, new { id = "meuForm" } ))
{
...
...
...
<input type="submit" value="Enviar" id="btn-Enviar" />
<input onclick="enviarForm" type="button" value="Enviar Outro Action" id="btn-Enviar2" />
}

By clicking the button btn-Enviar the whole form is sent minhaAction in meuController.
My goal is that by clicking the button btn-Enviar2, that same form be sent to outraAction in meuController, then there I could receive the same FormCollection.
How could I do the function enviarForm?

1 answer

3


You could set 2 values with the same name for each button

<button type="submit"name="minhaaction" value="Action 1">
<button type="submit"name="minhaaction" value="Action 2">

and in its Action, carry out the verification for each of the cases

public ActionResult MinhaAction(string minhaaction)
{
   if(minhaaction == "Action 1") { 
     //realiza action 1
   }else {
    //Realiza action 2
   }
}
  • @bigown on db? I posted again, ended up publishing 2 times, so I deleted one, sorry...I could reply yes, thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.