I have a from where i want to have a editor for a start- and end-time.
So i created a EditorTemplate in path 'Views/Shared/EditorTemplates/Time.cshtml'.
@model string
@{
var htmlAttributes = this.GetControlHtmlAttributes();
htmlAttributes.AddClass("time");
htmlAttributes.AddAttribute("style", "background-color: fuchsia");
}
@Html.TextBoxFor(m => m, htmlAttributes: htmlAttributes)
In my view, i call
<td>
@Html.EditorFor(m => m[i].kal_von)
</td>
<td>
@Html.EditorFor(m => m[i].kal_bis)
</td>
(just note: it does not work if i call it like this:
<td>
@Html.EditorFor(m => m[i].kal_bis, "Time")
</td>
)
and the model looks like this:
[StringLength(5)][DataType(DataType.Time)][DataMember(EmitDefaultValue = false)]
[DisplayNameAttribute("d_kal_termin.kal_von")]
public string kal_von { get; set; }
[StringLength(5)][DataType(DataType.Time)][DataMember(EmitDefaultValue = false)]
[DisplayNameAttribute("d_kal_termin.kal_bis")]
public string kal_bis { get; set; }
Thanks!!
Do you have something like this in your code? Where you replace the default RazorViewEngine?
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new AppRazorViewEngine());
If so, make sure your custom ViewEngine contains the path to your EditorTemplates directory.