In asp.net mvc3 razor view how to bind the list of strings in the listbox with the single selection. I am trying to bind list of Names (List) with the ListBox.
**Model**
Class StudentInfo
{
public string id{get,set};
public string names{get,set};
}
**In Conrtoller**
[HTTPGet]
public ActionResult Student()
{
List<StudentInfo> liststudent=new LIst<StudentInfo>{
new StudentInfo{id="v11",names="AB"},
new StudentInfo{id="v12",names="SA"},
return View(liststudent)
}
}
[HTTPPost]
public ActionResult Student(string name)
{
return View()
}
}
**In View**
<div class="alignright">
@using (Html.BeginForm())
{
@Html.ListBox("MyList",new SelectList(???));
}
</div>
The problem I am encountering are: 1. How to display the names of the student in the listbox. 2. How to provide an action with the selection.