Input submit does not call ActionResult

1

I'm having trouble calling ActionResult using input type="submit" and passing the model data.

I did a test using ActionLink but the Model is not sent.

Could someone give a light?

Follow the code: Controller:

[HttpPost]
public ActionResult Aprovar(FormularioModel model)
{
//Código
}
[HttpPost]
public ActionResult Devolver(FormularioModel model)
{
//Código
}

View:

 @using (Html.BeginForm(null, "Domiciliacao", FormMethod.Post, new { id = "formFila" })) 
    {
@Html.Partial("~/Views/Shared/ViewPartial.cshtml", Model) //PartialView sendo carregada para complentar os dados da tela.
//Código
    <div>               
                    <input type="submit" value="Aprovar" name="Aprovar" formmethod ="post" formaction="~/Domiciliacao/Aprovar" class="btn btn-success btn-lg"/>
                </div>
                <div>                
                    <input type="submit" value="Devolver" name="Devolver" formmethod ="post" formaction="~/Domiciliacao/Devolver" class="btn btn-danger btn-lg"/>
                </div>
    }
    
asked by anonymous 17.05.2017 / 22:05

2 answers

0

The beginForm uses two parameters: Action and Controller. Example

@using (Html.BeginForm("SuaAction", "SeuController", FormMethod.Post, new { @role = "form", @id = "frm", enctype = "multipart/form-data" }))
{

}
    
18.05.2017 / 00:29
0

There are a few ways to do this.

I changed some things in HTML:

@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "formFila" })) 
{
    @Html.Partial("~/Views/Shared/ViewPartial.cshtml", Model){
        <div>               
           <input type="button" value="Aprovar" name="Aprovar" data-formaction="~/Domiciliacao/Aprovar" class="btn btn-success btn-lg btn-submit"/>
        </div>
        <div>                
           <input type="button" value="Devolver" name="Devolver" data-formaction="~/Domiciliacao/Devolver" class="btn btn-danger btn-lg btn-submit"/>
        </div>
    }
}

I used jquery for you to see:

$(document).ready(function(){
   $("#formFila .btn-submit").click(function(){
      var form = $("#formFila");
      form.attr("action", $(this).data("formaction");
      form.submit();
   });
});

If you're going to use it with jquery, do not forget the lib reference: link

Or, as a suggestion has already been made, you can do two forms. One for each situation.

    
18.05.2017 / 15:43