-2
如何在ASP MVC 5中創建IEnumerable
下拉列表?創建IEnumerable DropDownList
我用這一點,但它爲我的錯誤:
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>
具有關鍵 'Reshte' 的類型爲 'System.Int32' 的ViewData的項目但必須是「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 –
好的。謝謝 。你有指導嗎? – Kianoush
你可以添加你使用的模型類嗎? – CodeNotFound