I need to populate two listboxes with data from a database.
But I need to display two listboxes in one view, so I created a ListBoxModel class.
public class ListboxModel
{
public ListBox LB1 { get; set; }
public ListBox LB2 { get; set; }
}
And in my Controller:
public ActionResult IndexStudents(Docent docent, int lessonid, int classid)
{
var MyListBox = new ListboxModel
{
LB1 = new ListBox(docent.ReturnStudentsNormal(lessonid, classid),
LB2 = new ListBox(docent.ReturnStudentsNoClass(lessonid, classid)
};
return View(MyListBox);
}
But this code does not work, how can I bind the data to the listboxes?
So I'd like to use 2 models, one for each listbox... one with normal students and one with students who are not subscribed for lessons.
How could I do that?
And what code do I have to write in my view?
Something like:
<div class="editor-field">
<%: Html.ListBox("IndexStudentsNormal", Model.LB1) %>
<div class="editor-field">
<%: Html.ListBox("IndexStudentsNoClass", Model.LB2) %>
The listbox has to be a listbox with multiple colums so that it can contain the name, sirname, class, teacher of the student.
Student is an object, I'd like to display student.Name, student.Sirname, student.Class, and so on in that listbox.
So can I use an object in a ListBox, or do I have to convert everything to strings?
How can I do that?
Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…