I'm obviously still missing something about how to bind the selected item in a DropDownList.
I set up the SelectList like this in a repository:
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)));
}
Then in the controller, this:
ViewData["AgenciesDonorList"] = repo.GetAgencyList(donorId, ccResult.AgenciesDonors.AgenciesDonorId);
return View(ccResult);
And in the view, this:
<%=Html.DropDownList("AgenciesDonorList", (IEnumerable<SelectListItem>)ViewData["AgenciesDonorList"])%>
In the debugger right before return View(...), I can see the proper item is selected (true) and all others are false. But in the view, the select option never makes it, and the first time is always shown.
Does this have nything to do with my use of int as the selected param?
Thx. Dale