0

RelationshipCodeLookupのテーブルは、テーブルの主キー フィールドを外部キーとして使用しAgentTransmissionます。同じ主キーRelationshipCodeLookupを持つテーブルには5 つのレコードしか存在できません。AgentTransmission

これをコーディングするために、モデルに 5 つRelationshipCodeLookupのオブジェクトを作成しました。すべて正常に動作します (作成/編集/削除) が、日付のみを表示するAgentTranmsissionことができません。EffectiveDate

エージェント送信

namespace Monet.Models
{
  public partial class AgentTransmission
  {
    public RelationshipCodeLookup RelationshipCode1 { get; set; }
    public RelationshipCodeLookup RelationshipCode2 { get; set; }
    public RelationshipCodeLookup RelationshipCode3 { get; set; }
    public RelationshipCodeLookup RelationshipCode4 { get; set; }
    public RelationshipCodeLookup RelationshipCode5 { get; set; }

    public int ID { get; set; }
    public Nullable<System.DateTime> EffectiveDate { get; set; }
    public Nullable<System.DateTime> TerminationDate { get; set; }
    public string InactiveReasonCode { get; set; }
    public string RecordStatus { get; set; }
    public string EntityType { get; set; }
    public string ReferenceType { get; set; }
   }
}

RelationshipCodeLookup

namespace Monet.Models
{
    [MetadataType(typeof(RelationshipCodeLookupMetaData))]
    public partial class RelationshipCodeLookup1
    {
        public int Id { get; set; }
        public string RelationshipId { get; set; }
        public Nullable<System.DateTime> EffectiveDate { get; set; }
        public System.DateTime LastChangeDate { get; set; }
        public string LastChangeId { get; set; }
    }
    class RelationshipCodeLookupMetaData
    {
        [DisplayName("Effective Date")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
        public Nullable<System.DateTime> EffectiveDate { get; set; }        
    }
}

意見

    <tr>
        <td>@Html.EditorFor(model => model.RelationshipCode1.EffectiveDate, new { @class = "relCodeDate1" })</td>
        <td>@Html.TextBoxFor(model => model.RelationshipCode1.RelationshipId, new { @class = "relDistCode1", maxlength = 3 })</td>
    </tr>
    <tr>
        <td>@Html.EditorFor(model => model.RelationshipCode2.EffectiveDate, new { @class = "relCodeDate2" })</td>
        <td>@Html.TextBoxFor(model => model.RelationshipCode2.RelationshipId, new { @class = "relDistCode2", maxlength = 3 })</td>
    </tr>
    <tr>
        <td>@Html.EditorFor(model => model.RelationshipCode3.EffectiveDate, new { @class = "relCodeDate3" })</td>
        <td>@Html.TextBoxFor(model => model.RelationshipCode3.RelationshipId, new { @class = "relDistCode3", maxlength = 3 })</td>
    </tr>
    <tr>
        <td>@Html.EditorFor(model => model.RelationshipCode4.EffectiveDate, new { @class = "relCodeDate4" })</td>
        <td>@Html.TextBoxFor(model => model.RelationshipCode4.RelationshipId, new { @class = "relDistCode4", maxlength = 3 })</td>
    </tr>
    <tr>
        <td>@Html.EditorFor(model => model.RelationshipCode5.EffectiveDate, new { @class = "relCodeDate5" })</td>
        <td>@Html.TextBoxFor(model => model.RelationshipCode5.RelationshipId, new { @class = "relDistCode5", maxlength = 3 })</td>
    </tr>

スクリーンショット

ここに画像の説明を入力

4

1 に答える 1

3

次のような独自のエディター テンプレートを作成します (Views/Shared/EditorTemplates):

@model DateTime?

@Html.TextBox("", (Model.HasValue ? Model.Value.ToString("MM/dd/yyyy") : string.Empty), new { @class = "form-control" })

次に、次のように使用します。

@Html.EditorFor(m => m.EffectiveDate, "NullableDate")

.ToString()これが行っているのは、完全な日付と時刻を提供するデフォルトの呼び出しをオーバーライドすることだけです。

于 2013-11-13T23:02:20.703 に答える