我遇到問題,首先在實體框架數據庫中爲我的外鍵字段獲取正確的顯示名稱。爲表示我有同樣的問題here顯示名稱外鍵字段的數據註釋
我的類:
public class CampaignMeta
{
public long CampaignID;
[Required]
[Display(Name = "Campaign Name")]
public string CampaignName;
[Display(Name = "Campaign date created")]
public Nullable<System.DateTime> DateCreated;
public Nullable<System.DateTime> DateEnded;
[Display(Name = "Campaign Type")]
public Nullable<long> CampaignTypeID;
public virtual CampaignType CampaignType {get;set;}
}
我的一些看法(問題區域):
<div class="form-horizontal">
<h4>Campaign</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.CampaignName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CampaignName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CampaignName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DateCreated, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DateCreated, new { htmlAttributes = new { @class = "form-control datepicker col-md-2", placeholder = "Enter Drop-off date here..." } })
@Html.ValidationMessageFor(model => model.DateCreated, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DateEnded, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DateEnded, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DateEnded, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CampaignTypeID, "CampaignTypeID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("CampaignTypeID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.CampaignTypeID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
我的外鍵是CampaignTypeID並顯示CampaignTypeID代替「廣告系列類型」。我在這樣的場景中誤解了什麼?
不應該有問題。但是,這在很大程度上取決於您如何渲染視圖中屬性的標籤*,這是您忽略發佈的內容。假設你正在使用類似'LabelFor'的東西,那麼顯示名稱應該適用。 –
嗨@ChrisPratt,我確實有LabelFor,但它仍然不會budge ..我有這個問題呃請看原來的帖子爲標記的視圖.. – JJDev