Hi,
I have a site that was using ASP.Net MVC Beta 5, and I have just upgraded it to ASP.Net MVC 1.0. I am having trouble with the selected item in a drop down list.
The follow person has a similar question (http://stackoverflow.com/questions/589935/html-dropdownlist-in-asp-net-mvc-rc-refresh-not-pre-selecting-item) but I there is no answer (other than it might be a bug)
My Controller method looks as follows:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult View(Guid id)
{
IntegrationLogic logic = new IntegrationLogic(new IntegrationLinq());
CompanyLogic companyLogic = new CompanyLogic(new CompanyLinq());
IntegrationContainer container = new IntegrationContainer();
container.Sources = logic.GetImportSource(id);
container.Companies = companyLogic.GetCompanies(); // Returns a IList<company>
container.SourceActions = logic.GetAllSourceActions(); // Returns an IList<SourceAction>
container.SinkActions = logic.GetAllSinkActions();
container.SuccessActions = logic.GetAllSuccessActions();
container.FailureActions = logic.GetAllFailureActions();
container.Actions = logic.GetAllActions();
container.Watchers = logic.GetAllWatcherActions();
container.ChainActions = logic.GetAllChainActions();
return View("View", container);
}
The view is a strongly typed against the Model as follows
public partial class View : ViewPage<IntegrationContainer> {}
The problem area in the view template is :
<label for="Companies">Company: </label><%=Html.DropDownList("Companies",
new SelectList(ViewData.Model.Companies, "id", "name", item.CompanyID))%>
I am creating a Dropdown List, the selected item never actually gets selected - and that is the problem. "item.CompanyID" is a Guid, "id" is a Guid and "name" is a string on the company object supplied in the IList that is held in the ViewData.Model.Companies instance.
Is this actually a bug ?- I find it hard to understand why this is still present in ASP.Net MVC... I would be totally happy if it is something I have done.
Regardless, what would be the suggested work around?
Thanks