Hi buddy,
You just need to do below thing,
Create a property in your Model class
public List<selectlistitem> Names{get;set;}.
Then just create method in model class
Public List<selectlistitem> GetNames()
{
var names=new List<selectlistitem>();
names.add(new SelectListItem{
Text="1",
Value="1"});
names.add(new SelectListItem{
Text="1",
Value="1"});
names.add(new SelectListItem{
Text="1",
Value="1"});
return names;
}
Then in constructor of model
public ModelClassName()
{
Names=GetNames();
}
Then, call this model from controller and pass the model to view
Now you just have to right in view
@Html.DropDownListFor(model => model.name, model.Names, new { id = "ddlClass", @class = "field04" })
If you find this useful then please vote for this.
Thanks.