ASP .NET MVC - Use an @Html.DropDownList for two ActionResult

0

Hello,

I'm developing an application with ASP .NET MVC and using the EPPlus API for XLS export.

In the View of an equipment report I have two @Html.DropDownList with Equipment Type and Status respectively.

To display the report I am working with a Input of type Submit named Filter , which sends Id both Type and Status for the query in the database through ActionResult of the view itself.

How could I use these same% 2 of% to send, from% Export , the parameters to another DropDownList of my Input who will do the same search and will return an XLSX?

Follow the cshtml code snippet:

<div class="ibox-content">
<div class="row">
    @using (Html.BeginForm())
    {
        <div class="col-sm-5 m-b-xs">
            @Html.DropDownList("TipoEquipamento", null, htmlAttributes: new { @class = "input-sm form-control input-s-sm inline" })
        </div>
        <div class="col-sm-5 m-b-xs">
            @Html.DropDownList("StatusEquipamento", null, htmlAttributes: new { @class = "input-sm form-control input-s-sm inline" })
        </div>
        <div class="col-sm-3">
            <div class="input-group">
                <input type="submit" value="Filtrar" class="btn btn-primary" />
            </div>
        </div>
    }

    @using (Html.BeginForm("ExportarDados", "Signv", FormMethod.Get))
    {
        <div class="col-sm-3">
            <div class="input-group">
                <input type="submit" value="Exportar" class="btn btn-primary" />
            </div>
        </div>
    }
</div>

Following the structure of the actions of my controller:

    [HttpPost]
    public ActionResult Index(int TipoEquipamento, int StatusEquipamento)
    {
       .... Código da Action...
    }

    public ActionResult ExportarDados(int TipoEquipamento, int StatusEquipamento)
    {
        .... Código da Action...
    }
    
asked by anonymous 19.10.2017 / 19:50

1 answer

1

I had to do something like this one time, call two actions different passing the same thing, in my case it was a model, I did this:

I placed everything inside the same BeginForm , a submit button points to the action declared within BeginFiorm as you already did, and the other submit button > as below:

<input  type="submit" formaction="@Url.Action("OutraAction", "MesmoController")">

I think it will work for what you said the first Action is already working right.

I think there might be something like this:

<div class="ibox-content">
<div class="row">
@using (Html.BeginForm("Index", "Signv", FormMethod.Get))
{
        <div class="col-sm-5 m-b-xs">
        @Html.DropDownList("TipoEquipamento", null, htmlAttributes: new { @class = "input-sm form-control input-s-sm inline" })
    </div>
    <div class="col-sm-5 m-b-xs">
        @Html.DropDownList("StatusEquipamento", null, htmlAttributes: new { @class = "input-sm form-control input-s-sm inline" })
    </div>
    <div class="col-sm-3">
        <div class="input-group">
            <input type="submit" value="Filtrar" class="btn btn-primary" />
        </div>
    </div>
    <div class="col-sm-3">
        <div class="input-group">
            <input type="submit" value="Exportar" class="btn btn-primary" />
        </div>
    </div>
    <div class="col-sm-3">
        <div class="input-group">
            <input  type="submit" formaction="@Url.Action("ExportarDados", "Signv")">
        </div>
    </div>
}

    
20.10.2017 / 14:56