これは私のコントローラーアクションです
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 アイテムはありません」というエラーが表示されます。