Hello,
Basically for creating a DropDownListFor you will need to declare the parameters below
@Html.DropDownListFor (,)
Model:
public class Veiculo
{
public int ID { get; set; }
public string Tipo { get; set; }
public int idModeloVeiculo { get; set; }
}
public class ModeloVeiculo
{
public int ID { get; set; }
public string Descricao { get; set; }
}
Action MVC:
[Controller]
ViewData["idModeloVeiculo"] = new SelectList(contexto.ModeloVeiculos.toList(),"ID","Descricao");
HTML:
@model Veiculo
@Html.DropDownListFor(m => m.idModeloVeiculo , null)
As we can see the View is strongly typed for the "Vehicle" class that has the "idModel" attribute of integer type. At the moment we created a ViewData in the controller with the same attribute name:
[Controller]
ViewData["idModeloVeiculo"] = new SelectList(contexto.ModeloVeiculos.toList(),"ID","Descricao");
Automatically .Net verifies that ViewData will be used in the "idVideoClick"
//Na verdade "m.idModeloVeiculo" é ViewData "idModeloVeiculo"
@Html.DropDownListFor(m => m.idModeloVeiculo , null)
Then change your code as follows:
public ActionResult ComboAffiliate()
{
FilterAffiliate Affiliate = new FilterAffiliate();
List<SelectListItem> model = Affiliate.filterAffiliate();
ViewData["Combo"] = new SelectList(Affiliate.filterAffiliate().ToList(),"ID","Descricao");
return PartialView(model);
}
Partial:
@model IBS_WEB.Models.Filters.FilterAffiliate
@Html.DropDownListFor(model => model.CD_AFFILIATE, ViewData["Combo"] ,new { @class ="ComboWidth" })
Follow the links.
link
link