ASP . NET MVC - Using a @Html.Dropdownlist for two Actionresult

Asked

Viewed 573 times

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 Type of Equipment and Status Respectively.

For the display of the report I am working with a Input of the kind Submit called Filter, who sends the Id so much of Type how much of Status for consultation in the database through the ActionResult of the view itself.

How could I use these same two DropDownList to send, from a Input Export, the parameters for another Action of my controller who will do the same search and return an XLSX?

Follow the snippet of cshtml code:

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

Follow my controller’s Actions structure:

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

    public ActionResult ExportarDados(int TipoEquipamento, int StatusEquipamento)
    {
        .... Código da Action...
    }

1 answer

1


I had to do something similar once, call two actions different passing the same thing, in my case was a model, I did this:

I put it all inside BeginForm, one Submit button points to the action declared within the BeginFiorm as you have done, and the other Submit button as below:

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

I believe it will work for what you said the first Action is already working well.

I think it might look 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>
}

  • Gave good! Thanks for the help!!

Browser other questions tagged

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