我需要从数据库中获取数据并将其填充到两个列表框中。 但是我需要在一个视图中显示两个列表框,因此我创建了一个ListBoxModel类。
public class ListboxModel
{
public ListBox LB1 { get; set; }
public ListBox LB2 { get; set; }
}
我的控制器中:
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);
}
但是这段代码不起作用,我该如何将数据绑定到列表框?所以我想使用两个模型,一个用于每个列表框......一个用于正常学生和一个用于未订阅课程的学生。我该怎么做?在我的视图中需要编写什么代码?类似以下内容:
<div class="editor-field">
<%: Html.ListBox("IndexStudentsNormal", Model.LB1) %>
<div class="editor-field">
<%: Html.ListBox("IndexStudentsNoClass", Model.LB2) %>
列表框必须是具有多列的列表框,以便可以包含学生的姓名、姓氏、班级和老师等信息。
学生是一个对象,我想在列表框中显示学生的姓名、姓氏、班级等信息。
那么我能在ListBox中使用一个对象吗,还是必须将所有内容转换为字符串?
如何实现呢?
谢谢!