Editor Templateを定義し、DateTimeプロパティの属性を[UIHint]
と設定するのはなぜですか?
例えば、[UIHint("{name of editor template}")]
[Required] // example of an annotation you might want to handle
[UIHint("Datepicker")]
public DateTime SelectedDate { get; set; }
がEditorFor
を持つプロパティをレンダリング使用してビュー/共有/ EditorTemplates/Datepicker.cshtml
@model DateTime
@{
IDictionary<string, object> htmlAttributes = new Dictionary<string, object>();
// TODO: retrieve annotations from Model Metadata and add html attributes accordingly, e.g. "required"
htmlAttributes.Add("data-datepicker", "");
}
<div class="@* TODO: set classes depending on your CSS framework *@">
@Html.TextBox("", Model, htmlAttributes)
</div>
属性あなたのviewmodelsを作成し、これは正しいテンプレート
に派遣します
@Html.EditorFor(m => m.SelectedDate)
私はあなたがemplating:https://stackoverflow.com/questions/37674824/templating-in-asp-net-core –