【问题标题】:Html.DropDownList size attributeHtml.DropDownList 大小属性
【发布时间】:2017-05-11 17:52:01
【问题描述】:

这是 HTML

<select size="25" style="width:100px" id="yearList"/>

这是 Razor(不确定这是否正确)

@Html.DropDownList("yearList", null, new{style="width:100px;"})

有谁知道如何给 Razor 版本赋予类似于 HTML 版本的 size 属性?

非常感谢。

【问题讨论】:

    标签: asp.net-mvc razor


    【解决方案1】:

    像这样:

    @Html.DropDownList(
        "yearList", 
        Enumerable.Empty<SelectListItem>(),  // <!-- TODO: bind with a real data
        new { 
            size = "25", 
            style = "width: 60px" 
        }
    )
    

    【讨论】:

    • size="5" 更多,所以我使用了new {style = "width:270px;height:30px" } 并且它有效。谢谢。
    • 如果它对任何人都有帮助:我不知道该怎么做:“Enumerable.Empty(), //
    【解决方案2】:

    打开 /Content/Site 设置选择类的宽度,这将自动反映在您的页面上

    select
    {
        width:250px;
    }
    

    【讨论】:

    • 不回答问题。 size attr 是行数,而不是宽度。
    猜你喜欢
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 2011-10-31
    • 2018-02-14
    • 2010-09-23
    • 1970-01-01
    • 2019-01-31
    • 1970-01-01
    相关资源
    最近更新 更多