私のAddcar
ビューで私は私のデータベース(テーブルCar
)にデータを挿入するフォームを許可しています。外部キーを使用してテーブルに挿入しますか?
テーブルCar
私は Categorie
テーブルに関連する外来キーです。
私のフォームに追加するには、ドロップダウンリストを用意して、追加したい車のカテゴリを選択できるようにする必要があります。
これは私のビューの一部である:これは私のコントローラのアクションが
<div class="editor-label">
<p>
<%: Html.LabelFor(model => model.Idcat) %>
</p>
</div>
<div class="editor-field">
<p>
<!-- in this dropDownList i want to show the all Name Of Marque in my forgien table and user when he select value wil be set at id of selected marque -->
<%: Html.DropDownListFor(model => model.Idcat, ViewBag.cat as SelectList)%>
<%: Html.ValidationMessageFor(model => model.Idcat) %>
</p>
</div>
です:
public ActionResult addcar()
{
ViewBag.cat = new SelectList(entity.categorie, "Idcat", "Nom");
return View();
}
私は彼がこのラインでの私は、このエラーThere is no ViewData item of type 'IEnumerable <SelectListItem>' with key 'Idcat'.
を示して作成上のCLICまで、この作業罰金<%: Html.DropDownListFor(model => model.Idcat, ViewBag.cat as SelectList)%>
私の投稿を更新しました。確認してください。 – Chlebta