علت خطای زیر چیست؟
در ActionResult مربوطه کد
ViewBag.BankID = new SelectList(db.Bank, "BankID", "BankName");
آمده است.
در صفحه مربوطه کد
<div class="form-group"> @Html.LabelFor(model => model.BankID, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.DropDownList("BankID", String.Empty) @Html.ValidationMessageFor(model => model.BankID) </div> </div>
آمده است.
Additional information: The ViewData item that has the key 'BankID' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'.
سلام دوست عزیز
از این روش استفاده کنید
var db = new DB(); IEnumerable<SelectListItem> basetypes = db.Basetypes.Select( b => new SelectListItem { Value = b.basetype, Text = b.basetype }); ViewData["basetype"] = basetypes;
<div class="form-group"> @Html.LabelFor(model => model.BankID, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.DropDownList("BankID") @Html.ValidationMessageFor(model => model.BankID) </div> </div>
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)