EditorTemplates - Sharing between Date.cshtml and DateTime.cshtml

I have an editor template for DateTime and Date. The content of Date is a simple copy and paste from DateTime. This is a terrible copy and paste.

Is there a good way for decorated properties to [DataType(DataType.Date)]use the DateTime editor template? How about directions from a Date template to use a DateTime template with some ViewData information added?

+4
source share
1 answer

How much code is in your editor templates?

, , - , HTML , () HTML- .

, :

_Layout.cshtml

<p>
    @Html.LabelFor(m => m):
</p>
<p>
    @RenderSection("value")
</p>
<p>
    @Html.ValidationMessageFor(m => m)
</p>

, :

String.cshtml

@model System.String
@{
    Layout = "~/Views/Shared/EditorTemplates/_Layout.cshtml";
}
@section value{
    @Html.TextBoxFor(m => m)
}

Password.cshtml

@model System.String
@{
    Layout = "~/Views/Shared/EditorTemplates/_Layout.cshtml";
}
@section value{
    @Html.PasswordFor(m => m)
}
+3

All Articles