Monday, July 25, 2011

Asp.net MVC, DropDownList and Selected Value

My ASP.NET MVC Dropdownlist selected value was not displaying even after setting the right paramters. After a while, following article helped me to fix this

http://weblogs.asp.net/ashicmahtab/archive/2009/03/27/asp-net-mvc-html-dropdownlist-and-selected-value.aspx

For me, the code was as below

ViewBag.ddlDim = new SelectList(BusinessDimensionMethods.getDimensions(), "dimCode", "dimDesc",selDim);

My View was as below

@{
@Html.DropDownList("ddlDim", (SelectList)ViewBag.ddlDim, new Dictionary

{
{"class", "dropdown"},
{"style", "width: 200px"},
{"onChange", "onFilter()"}

});
}


after changing the name ddlDim to ddlDimension in html Dropdown control My issue is fixed now.

No comments: