-1
我已經對這個錯誤了一會兒和ienumerable
物體阻擋有人可以請幫助我的錯誤是在描述。有型的無ViewData的項目「的IEnumerable <SelectListItem>」具有關鍵「BranchQuickChange」
HTML:
@model IEnumerable<DatabaseDAL.Models.WAGTripHdr>
<script type="text/javascript" src="~/Scripts/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$("select#BranchQuickChange").change(function() {
var branchName = $("select#BranchQuickChange option:selected").text();
alert(branchName);
window.location.href = '@Url.Action("QuickBranchChange", "TripSheets")?branchName=' + branchName;
});
</script>
<div class="row-fluid">
<div class="span4" style="margin-top: 15px">
@if (User.IsInRole("Administrator") || User.IsInRole("SuperUser"))
{
<strong>Quick Switch</strong> @Html.DropDownList("BranchQuickChange",ViewBag.CompanyList as SelectList)
}
</div>
控制器:
{
List<WAGBranch> listWagBranch = WAGBranchRepository.GetAllBranches(CompanyEnum.WAG).OrderBy(i => i.BRName).ToList();
List<string> listCompany = new List<string>();
foreach (WAGBranch branch in listWagBranch)
{
listCompany.Add(branch.BRName); // + " - " + branch.Branch);
}
//listCompany.Insert(0, "WAG HEAD OFFICE - WAG");
if ((string)selected == "") selected = null;
ViewBag.CompanyList = new SelectList(listCompany, selected);
}
型號:
[TableNameAttribute("WAGTripHdr")]
public class WAGTripHdr : SQLSelectUpdateInsertHelper
{
public string DebName { get; set; }
}
等待一些建議。通常當傳遞給DropDownListFor
集合爲空時