zoukankan      html  css  js  c++  java
  • MVC RC2中关于HtmlHelper给DropDownList设置初始选中值的问题

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

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

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

    Code

    调用代码如下:

    Action部分:

    List<SelectListItem> _items = new List<SelectListItem>();
            
    ViewData[
    "Citys"= _items;

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

    作者:菩提树下的杨过
    出处:http://yjmyzz.cnblogs.com
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    go语言圣经第8章Goroutines 和 Channels
    VSCODE远程开发 golang环境配置
    golang排序简述
    go语言圣经第七章笔记-接口
    Java并发编程小记
    [Effective Modern C++] Item 7. Distinguish between () and {} when creating objects
    [Effective Modern C++] Item 6. Use the explicitly typed initializer idiom when auto deduces undesired types
    [Effective Modern C++] Item 5. Prefer auto to explicit type declarations
    [Effective Modern C++] Item 4. Know how to view deduced types
    [Effective Modern C++] Item 3. Understand decltype
  • 原文地址:https://www.cnblogs.com/yjmyzz/p/1412507.html
Copyright © 2011-2022 走看看