How to get DB values in the controller session in sight and close as soon as the session closes?

1

This was an old query and I get the idea out of it (

I need to take those Values to the controller, I would have to save them in Parameters of the ShopParameters type along with the dates, after storing them in parameters they will be sent to the QueryMethod (parameters) where the query will be made to return the query result and then upload it in a pdf. if there is another way to do that exercise I would appreciate all information, thanks )

This is my view:

@model Tienda.net.Controllers.Reportes.TiendaParametros

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

@using (Html.BeginForm("TiendaAction", "ControllerTienda", new { id = "PDF" }, FormMethod.Post))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    
    <fieldset>
        <div class="editor-label">
            @Html.LabelFor(model => model.FechaInicio)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FechaInicio)
            @Html.ValidationMessageFor(model => model.FechaInicio)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.FechaFinal)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FechaFinal)
            @Html.ValidationMessageFor(model => model.FechaFinal)
        </div>
        <div class="row">
          <div class="col-md-3">
              Colegio<br />
              <select name="singleSelect"class="form-control">
                <option value="1">manzana</option>
                <option value="3">tomate</option>
                <option value="8">zandia</option>
                <option value="9">melon</option>
                <option value="4">naranja</option>       <!-- quiero que toda esta informacion me cargue en una DropDownList -->
                <option value="5">limon</option>
                <option value="2">mora</option>
                <option value="7">frutilla</option>
              </select>
          </div>
        </div>
        

        <p>
            <br />
            <input type="submit" value="Create" />
        </p>

    </fieldset>
}


@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

this is my controller

public ActionResult TiendaAction(TiendaParametros parametros, string id)
        {
            LocalReport lr = new LocalReport();
            string path = System.IO.Path.Combine(Server.MapPath("~/Reportes"), "Frutas.rdlc");
            if (System.IO.File.Exists(path))
            {
                lr.ReportPath = path;
            }
            else
            {
                return View("Index");
            }

            ReportDataSource rd = new ReportDataSource("DTfrutas", MetodoConsulta(parametros).Tables[0]);

            ReportParameter[] parameters = new ReportParameter[2];

            lr.DataSources.Add(rd);
            string reportType = id;
            string mineType;
            string encoding;
            string fileNameExtension;

            string deviceInfo =
                "" +
                "" + id + "" +
                "8.5in" +
                "11in" +
                "0,787402in" +
                "0,787402in" +
                "0,787402in" +
                "0,787402in" +
                "";

            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes;

            renderedBytes = lr.Render(
                reportType,
                deviceInfo,
                out mineType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);
            return File(renderedBytes, mineType);
        }

 

this my ShopParameters class:

public class TiendaParametros
{
   public DateTime FechaInicio { get; set; }
   public DateTime FechaFinal { get; set; }
   public int CodFruta { get; set; }
}
    
asked by Rodrigo Rodriguez 03.10.2017 в 15:38
source

2 answers

0

Good morning, I hope I will help you

you declare in the drivers that you want this session to be open.

  public ActionResult Index()
        {

        IList<FrutaModel> fruta = (IList<FrutaModel>)Session["FrutaSeleccionada"];

        ViewBag.idfruta = new SelectList(fruta, "Idfruta", "Nombre");


        return View();
        }

Your fruit model:

    public class ColegioModel
{
    public int IdFruta { get; set; }
    public string nombre { get; set; }
}

the view:

@model SIGA.net.Controllers



@{
    ViewBag.Title = "Index";
}
@using (Html.BeginForm("ClassController", "MetododelControlador", new { id = "PDF" }, FormMethod.Post))
    {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)


            
                Fruta:
                @Html.DropDownList("IdFruta", null, htmlAttributes: new { @class = "form-control" })
            
    }

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

    
answered by 23.10.2017 / 23:29
source
0

Just rename your select to:

<select name="CodFruta" id="CodFruta" class="form-control">

With this, your property CodFruta of your model TiendaParametros will come with the selected value.

    
answered by 03.10.2017 в 19:02