【问题标题】:Using Data Annotations to define which attribute should be used as DropDown Text?使用 Data Annotations 定义应将哪个属性用作 DropDown Text?
【发布时间】:2017-10-15 20:49:12
【问题描述】:

我有以下型号:

public class Bus
    {
        public int ID { get; set; }
        [Required]
        public string From { get; set; }
        [Required]
        public string To { get; set; }
        [Required]
        public string Label { get; set; }

    }

当我这样做时:

@Html.DropDownList("BusID", null, htmlAttributes: new { @class = "form-control" })

下拉文本标签是“发件人”属性。

我想知道是否有任何方法可以通过数据注释来定义在呈现下拉列表时将哪个字段用作“文本”?

谢谢!

【问题讨论】:

标签: entity-framework model-view-controller data-annotations


【解决方案1】:

您无法通过数据注释定义使用的属性,但您可以使用 DropDownListFor-Method 来完成,正如我在评论中提到的那样。

【讨论】:

    猜你喜欢
    • 2019-11-09
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    • 2012-08-09
    • 1970-01-01
    • 1970-01-01
    • 2012-02-05
    相关资源
    最近更新 更多