我显然仍然缺少一些关于如何绑定DropDownList中的选定项。DropDownList项未选中
我设置这样选择列表的一个库:
public SelectList GetAgencyList(System.Guid donorId, Int32 selected)
{
AgenciesDonorRepository adRepo = new AgenciesDonorRepository();
List<AgenciesDonor> agencyDonors = adRepo.FindByDonorId(donorId);
IEnumerable<SelectListItem> ad = from a in agencyDonors
select new SelectListItem {
Text = a.Agencies.AgencyName,
Value = a.AgenciesDonorId.ToString()
};
return(new SelectList(ad, "Value", "Text", (selected == 0 ? 0 : selected)));
}
然后在控制器中,这样的:
ViewData["AgenciesDonorList"] = repo.GetAgencyList(donorId, ccResult.AgenciesDonors.AgenciesDonorId);
return View(ccResult);
并在视图,这样的:
<%=Html.DropDownList("AgenciesDonorList", (IEnumerable<SelectListItem>)ViewData["AgenciesDonorList"])%>
在返回View(...)之前的调试器中,我可以看到正确的项目被选中(true),而其他的都是false。但在视图中,选择选项永远不会生效,并且始终显示第一次。
这与我使用int作为选定的参数有什么关系吗?
Thx。戴尔
在什么... ASP? – Greg 2009-11-03 19:59:02
ASP.net MVC 1.0 – Dale 2009-11-03 20:40:10