Asp.Net MVC RC2中Helper提供的DropDownList好象并不太好用,特别想给下拉框设置初始选中值的时候(可能我还没找到正确的方法)

小试了一下,有二个简单的解决办法:
1.回到最原始的asp的办法,直接在view的循环中判断,具体代码就不写了,有过Asp/Php经验的一点就明白

2.自己再写一个DropDownList的重载版本,如下:

 sb.ToString();

        }

调用代码如下:

Action部分:

List<SelectListItem> _items = new List<SelectListItem>();
MVC RC2中关于HtmlHelper给DropDownList设置初始选中值的问题        
ViewData[
"Citys"= _items;

View部分:
<%=Html.DropDownList("SelName",  (IEnumerable<SelectListItem>)ViewData["Citys"],item.CityId.ToString(),"onchange=\"alert('Test')\"") %>

相关文章:

  • 2021-12-10
  • 2022-12-23
  • 2021-09-17
  • 2021-10-13
  • 2021-05-31
  • 2021-09-21
  • 2021-05-31
猜你喜欢
  • 2022-12-23
  • 2021-08-20
  • 2021-09-01
  • 2022-12-23
  • 2021-09-19
  • 2021-12-04
相关资源
相似解决方案