How to send an IList data set from the Controller to the View?

0

I get an amount N of elements of the session, how can I send it to the view and show it in a DropdownList?

or as in windowsForm it is known as a combobox

public ActionResult Index()
    {
        IList<CModel> c = (IList<CModel>)Session["CSeleccionado"];
        ViewBag.C = new SelectList(co, "IdC", "Descripcion");  
        return View();
    }

my view is already linked with

@model S.Controllers.R.Param
@{
    ViewBag.Title = "Index";
}

I want to show it in the same view

    
asked by Rodrigo Rodriguez 04.10.2017 в 20:43
source

2 answers

1

If I understand your question well, you want to show the list of CMo that you have as options in your drop down. To achieve that it is necessary to pass your list that you have contained in your ViewBag as the second parameter of the DropDownList helper.

Something like this:

@Html.DropDownList("IdC", ViewBag.C as SelectList, new { @class = "form-control" })

or, to show a null value of 'Select an option'

@Html.DropDownList("IdC", ViewBag.C as SelectList, "Select an option", new { @class = "form-control" })
    
answered by 04.10.2017 / 23:31
source
0

This was my solution.

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

I hope you serve them

    
answered by 04.10.2017 в 21:47