【发布时间】:2013-05-24 06:35:41
【问题描述】:
这是我的控制器操作
public ActionResult AddNewPost(string subName)
{
ViewBag.CategoryID = new SelectList(from c in db.Categories where c.Status == true select c, "CategoryID", "CategoryName");
return View();
}
在视图中我已将下拉列表填充为
<td>
@Html.DropDownList("CategoryID", "-- Select --")
</td>
但是当我尝试访问控制器中的下拉值时,我得到了这个错误 “没有具有键 'CategoryID' 的 'IEnumerable' 类型的 ViewData 项。”
【问题讨论】:
-
你能写类别模型吗?
-
嗨,你能解决这个问题吗?
-
马杜,看我下面的帖子
标签: asp.net-mvc razor drop-down-menu