没有类型为“IEnumerable <selectlistitem>”的ViewData项具有键“student”。错误</selectlistitem>

时间:2012-10-16 06:50:35

标签: asp.net-mvc-3

我使用ASP.Net MVC3 Razor,

我有一个控制器,我将数据绑定

public Actionresult Index()
    {
        ViewBag.student= new SelectList(db.Collection, "ID", "Name"); 
ViewBag.student1= new SelectList(db.Collection, "ID", "Name"); 
return view(); 
  }

这是我的观点

<table>
<tr>
    <td>
    @Html.DropDownList("student")

    </td>
    <td>

    @Html.DropDownList("student1")
    </td>
    </tr>
</table>

我的代码有什么问题,任何人都可以帮助我...... Thanx提前..

1 个答案:

答案 0 :(得分:0)

public Actionresult Index()
{
    ViewBag.studentList = new SelectList(db.Collection, "ID", "Name"); 
    ViewBag.student1List = new SelectList(db.Collection, "ID", "Name"); 
    return view(); 
}

<table>
<tr>
    <td>
    @Html.DropDownList("student", (SelectList)ViewBag.studentList)

    </td>
    <td>

    @Html.DropDownList("student1", (SelectList)ViewBag.student1List)
    </td>
    </tr>
</table>