Hello,
Basically for the creation of 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 class "Vehicle" that has the attribute "idModel" of the whole type. The moment we create a Viewdata in the controller with the same attribute name :
[Controller]
ViewData["idModeloVeiculo"] = new SelectList(contexto.ModeloVeiculos.toList(),"ID","Descricao");
Automatically . Net checks that the Viewdata "idModel will be used"
//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" })
Follows links.
https://stackoverflow.com/questions/3057873/how-to-write-a-simple-html-dropdownlistfor
https://stackoverflow.com/questions/7142961/mvc3-dropdownlistfor-a-simple-example
I’ll take a look here. vlw
– Paulo Henrique