send the selected option value of the view to the MVC controller

0

when you press any of these two tabs

<li class="active"><a data-toggle="tab" href="#Saldos">Saldos</a></li>
<li><a data-toggle="tab" href="#resumen">Resumen</a></li></ul>

I want you to send these values to the controller:

Balances = 1

summary = 2

in the view I also have the date, which works normally

View:

@model PROYECT.Controllers.ModelParametros

<div class="modal-header">
    <h2 class="modal-title" id="gridSystemModalLabel"><i class="glyphicon glyphicon-list-alt"></i> Reportes </h2><br />
    <ul class="nav nav-tabs">
        <li class="active"><a data-toggle="tab" href="#Saldos">Saldos</a></li>
        <li><a data-toggle="tab" href="#resumen">Resumen</a></li>
    </ul>
    <div class="col-md-12">
      @Html.LabelFor(model => model.ResumenFechaInicio, "Fecha Inicio  : ")
      @Html.EditorFor(model => model.ResumenFechaInicio, new { htmlAttributes = new { @class = "width200" } })
      @Html.ValidationMessageFor(model => model.ResumenFechaInicio)
    </div>
</div>

My model where I declare my parameters:

public class ModelParametros
{
public int TipoReporte { get; set; }
[Required(ErrorMessage = "Ingrese una Fecha Valida")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
[DataType(DataType.Date)]
public DateTime FechaInicio { get; set; }
}

in Model Parameters arrives Start Date = 07/07/2107 and in the type of refill I want it to arrive TypeReport = 1 or TipoReporte = 2 my controller:

public ActionResult Imprimir(ModelParametros parametros)
        {

        }
    
asked by 14.11.2017 в 16:48
source

1 answer

0

If I'm understanding what you're looking for, I can imagine a solution using jquery:

It would be necessary to put a html hidden element, and manipulate it according to the selection of the tab according to another hidden element inside each tab:

@model PROYECT.Controllers.ModelParametros

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <div class="modal-header">
        <h2 class="modal-title" id="gridSystemModalLabel"><i class="glyphicon glyphicon-list-alt"></i> Reportes </h2><br />
        @Html.Hidden("TipoReporte", "1")
        <ul class="nav nav-tabs">
            <li class="TipoReporteTab active"><input type="hidden" class="TipoReporteTab" value="1" /><a data-toggle="tab" href="#Saldos">Saldos</a></li>
            <li class="TipoReporteTab"><input type="hidden" class="TipoReporteTab" value="2" /><a data-toggle="tab" href="#resumen">Resumen</a></li>
        </ul>
        <div class="col-md-12">
            @Html.LabelFor(model => model.ResumenFechaInicio, "Fecha Inicio  : ")
            @Html.EditorFor(model => model.ResumenFechaInicio, new { htmlAttributes = new { @class = "width200" } })
            @Html.ValidationMessageFor(model => model.ResumenFechaInicio)
        </div>
        <input type="submit" value="Send" />
    </div>
}

@section scripts
{
    <script>
        $(function () {
            $('.TipoReporteTab').on('click', function () {
                $('#TipoReporte').val($(this).find(".TipoReporteTab").val());
            });
        });
    </script>
}
    
answered by 14.11.2017 в 21:49