Form with two destinations

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" />
}

When you click the btn-Enviar button all form is sent minhaAction to meuController . My goal is that by clicking the btn-Enviar2 button, that same form is sent to outraAction in meuController , so there I could receive the same FormCollection . Home How could I do function enviarForm ?

    
asked by anonymous 26.08.2015 / 19:56

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">

In your Action, perform the verification for each case

public ActionResult MinhaAction(string minhaaction)
{
   if(minhaaction == "Action 1") { 
     //realiza action 1
   }else {
    //Realiza action 2
   }
}
    
26.08.2015 / 20:29