如何获取外地的DisplayName?

时间:2015-12-10 19:12:01

标签: asp.net-mvc data-annotations

很抱歉,因为目前尚不清楚,但我试图通过上一个示例简化,我的实际模型如下:

public class Contractor
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    [Display(Name = "ID", ResourceType = typeof(Resources.Resources))]
    public decimal contractor_no { get; set; }

    [Display(Name = "Name", ResourceType = typeof(Resources.Resources))]
    public string contractor_name { get; set; }

    [Display(Name = "Contractor Class ID")]
    public string contractor_class_code_id { get; set; }

    [Display(Name = "Contractor Class Line")]
    public short contractor_class_code_line { get; set; }

    [ForeignKey("contractor_class_code_id, contractor_class_code_line")]
    [Display(Name = "Contractor Class")]
    public virtual CodeList CodeList_class { get; set; }

    [Display(Name = "Contractor Status ID")]
    public string contractor_status_code_id { get; set; }

    [Display(Name = "Contractor Status Line")]
    public short contractor_status_code_line { get; set; }

    [ForeignKey("contractor_status_code_id, contractor_status_code_line")]
    public virtual CodeList CodeList_status { get; set; }
}

public class CodeList
{
    [Key]
    [Column(Order = 0)]
    public string code_list_id { get; set; }

    [Key]
    [Column(Order = 1)]
    [Display(Name = "List Line")]
    public short code_list_line { get; set; }

    [Display(Name = "List Value")]
    public string code_value { get; set; }
}

我的问题是: 在视图中,字段“contractor_class_code_line”和“contractor_status_code_line”的名称始终相同,即“列表值”或“列表行”没有任何意义。

如何使用承包商模型中的名称“在这种情况下承包商类别行和承包商状态行”而不是代码模型中的名称?

2 个答案:

答案 0 :(得分:0)

好的,解决了

是:

@Html.LabelFor(model => model.contractor_class_code_line, "contractor_class_code_line", htmlAttributes: new { @class = "control-label col-md-2" })

更改为:

 @Html.LabelFor(model => model.contractor_class_code_line, htmlAttributes: new { @class = "control-label col-md-2" })

我错误地传递了标签文字。

答案 1 :(得分:-1)

我使用的效果非常好:

using System.ComponentModel;

您必须包含此使用声明:

npm i --save-dev babel-plugin-transform-decorators-legacy