-2
ASP MVC 5でIEnumerable
ドロップダウンリストを作成するにはどうすればよいですか?IEnumerable DropDownListを作成する
私はこれを使用していますが、それはエラーを私に示しています。 'Reshte' の型であるキーを持つ
public ActionResult EditStudent()
{
ViewBag.Reshte = new SelectList(_db.Tbl_Reshte, "ReshteID", "ReshteName");
ViewBag.Paye = new SelectList(_db.Tbl_Paye, "PayeID", "PayeName");
return View();
}
ビュー
<div class="form-group">
@Html.LabelFor(x => x.Reshte)
@Html.DropDownListFor(x => x.Reshte, (SelectList) ViewBag.Reshte, "-- رشته دانش آموز ---", htmlAttributes: new {@class = "form-control"})
</div>
<div class="form-group">
@Html.LabelFor(x => x.Paye)
@Html.DropDownListFor(x => x.Paye, (SelectList) ViewBag.Paye, "-- پایه تحصیلی دانش آموز --", htmlAttributes: new {@class = "form-control"})
</div>
ViewDataをアイテム '可能System.Int32'タイプ 'IEnumerable'でなければなりません。
public partial class Tbl_Reshte
{
public Tbl_Reshte()
{
Tbl_Pye_Reshte = new HashSet<Tbl_Pye_Reshte>();
}
[Key]
public int ReshteID { get; set; }
[StringLength(100)]
public string ReshteName { get; set; }
public virtual ICollection<Tbl_Pye_Reshte> Tbl_Pye_Reshte { get; set; }
}
。
public partial class Tbl_Paye
{
public Tbl_Paye()
{
Tbl_Pye_Reshte = new HashSet<Tbl_Pye_Reshte>();
}
[Key]
public int PayeID { get; set; }
[StringLength(100)]
public string PayeName { get; set; }
public virtual ICollection<Tbl_Pye_Reshte> Tbl_Pye_Reshte { get; set; }
}
正しいタイトルと最初の文:IEnumerable、IEnumerabelでない –
ok。ありがとう。私のためのガイドがありますか? – Kianoush
使用しているモデルクラスを追加できますか? – CodeNotFound