私のINV_Assets
モデルでは、次の日付フィールドが定義されています。
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? acquired_date { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? disposed_date { get; set; }
[Required]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public DateTime created_date { get; set; }
次に、私のEdit()
見解では、form-group
これらの Date 値ごとに次のように定義されています。
<div class="form-group">
@*@Html.LabelFor(model => model.acquired_date, htmlAttributes: new { @class = "control-label col-md-2" })*@
<span class="control-label col-md-2">Acquired Date:</span>
<div class="col-md-10">
@Html.EditorFor(model => model.acquired_date, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.acquired_date, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@*@Html.LabelFor(model => model.disposed_date, htmlAttributes: new { @class = "control-label col-md-2" })*@
<span class="control-label col-md-2">Disposed Date:</span>
<div class="col-md-10">
@Html.EditorFor(model => model.disposed_date, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.disposed_date, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@*@Html.LabelFor(model => model.created_date, htmlAttributes: new { @class = "control-label col-md-2" })*@
<span class="control-label col-md-2">Created Date:</span>
<div class="col-md-10">
@Html.EditorFor(model => model.created_date, new { htmlAttributes = new { @class = "form-control", @Value = Model.created_date.ToString("yyyy-MM-dd") } })
@Html.ValidationMessageFor(model => model.created_date, "", new { @class = "text-danger" })
</div>
</div>
さてcreated_date
、値がある場合、フォームを開くことができ、EditorFor
値が適切に表示されます。ただし、EditorFor()
foracquired_date
とは、データベースに値が保存されている場合でも、disposed_date
常に表示されます。エディターにデータベースの値が に変更されている間にフォームが保存された場合。mm/dd/yyyy
mm/dd/yyyy
null
acquired_date
and disposed_date
with (Ex.)@Value = Model.disposed_date.ToString("yyyy-MM-dd")
にand with (例)を指定しようとするとhtmlAttribute
、 both Model.acquired_date.ToString("yyyy-MM-dd")
and Model.disposed_date.ToString("yyyy-MM-dd")
flag as No overload method for 'ToString' takes 1 argument
...?
誰かが私が間違っていることを見ることができますか?
Date
理想的には、入力した値を、ユーザーが指定したものと保存時のEditorFor
現在の値で保存したいと考えています。ユーザーがレコードを表示している場合は、値を形式でTime
表示したいと思います。mm/dd/yyyy
EditorFor