在ASP.NET MVC中,当我给Html.DropDownList添加一个onchange属性时,会出现上述错误信息:
<td><%= Html.DropDownList("taskTypes", (IEnumerable<SelectListItem>)ViewData["TaskTypes"], "None", new { onchange = "document.getElementById('NewTask').submit()" })%></td>
当视图最初加载时,我不会得到错误。只有在更改所选项后进行回发时才会出现错误。我的控制器代码如下:
[AcceptVerbs(HttpVerbs.Get), RequiresAuthentication]
public ActionResult NewTask()
{
List<SelectListItem> dropDownData = new List<SelectListItem>();
List<SelectListItem> statusDropDownData = new List<SelectListItem>();
foreach (TaskStatus t in tasks.GetTaskStatus())
{
statusDropDownData.Add(new SelectListItem { Text = t.Status, Value = t.TaskStatusID.ToString() });
}
foreach (TaskType t in tasks.GetTaskTypes())
{
dropDownData.Add(new SelectListItem { Text = t.Reference, Value = t.TaskTypeID.ToString() });
}
ViewData["TaskStatus"] = statusDropDownData;
ViewData["TaskTypes"] = dropDownData;
if (Request["taskTypes"] != null)
{
string tt = Request["taskTypes"];
}
return View();
}
有人知道问题可能是什么吗?
谢谢