我想将 onchange 事件添加到我的下拉列表中

i want to add onchange event to my dropdownlist

问题是我有一个表格,在这个表格中我有一个下拉列表,其中包含来自数据库的学生姓名,我想每次 select 这个下拉列表中的任何值时都提交表格.当我尝试此代码时:

 @Html.DropDownList("StudentId", "--Select Students--", new { onchange = "this.form.submit();" })

我出现错误:

StudentId is a ViewBag containing List of Students come from database in controller action

试试这个:

new { @onchange = "this.form.submit();" })