単一のドロップダウン リストで始まるインデックス ページを作成したいと考えています。ユーザーがカテゴリを選択すると、(Ajax 呼び出しを介して) 2 番目のドロップダウン リストが表示され、ユーザーは編集するモデル アイテムを選択できます。ただし、コントローラーと以下のビューでコードを使用すると、次のエラーが発生します
The model item passed into the dictionary is of type 'System.Collections.Generic.List'1[Monet.Models.DropDownValues]', but this dictionary requires a model item of type 'Monet.Models.DropDownValues'.
コントローラ
public ActionResult Index()
{
//redirect if security is not met.
if (!Security.IsAdmin(User)) return RedirectToAction("Message", "Home", new { id = 1 });
var dropDownValues = (from b in db.DropDownValues
orderby b.Model
select b.Model).Distinct();
ViewBag.CategoryOptions = new SelectList(dropDownValues, "Model", "Model");
return View(db.DropDownValues.ToList());
}
意見
@model Monet.Models.DropDownValues
@{
ViewBag.Title = "Monet Administration";
}
<h2>Monet Administration</h2>
Update values for drop down boxes
<div>
<span style="float: left;">
<div class="editor-label">
@Html.LabelFor(model => model.Model)
</div>
<div class="editor-field">
@Html.DropDownList("Categories", (SelectList)ViewBag.CategoryOptions, "")
@Html.ValidationMessageFor(model => model.Model)
</div>
</span>
<div style="clear: both;"></div>
</div>