Follow the below steps for populating drop down in mvc razor
Step I:
Make a class in model like
public class student
{
public int id {get;set;}
public string Name {get;set;}
}
public class studentModel
{
public string SelectedStudent {get;set;}
public List<student> StudentList= new List<student>
{
new student {id=1,Name="Antariksh"},
new student {id=2,Name="Anurag"},
new student {id=3,Name="Anu"},
};
}
Step II:
In your controller code is like that:
[HttpGet]
public ActionResult Index()
{
StudentModel model= new StudentModel();
return view(model);
}
Step III:
In your view
@model projectName.models.StudentModel
@Html.DropDownListFor(x=>x.SelectedStudent,new SelectList(Model.StudentList, "id", "Name"), "--Please Select--")
I hope this will help you
Cheers!! :)