I'd like to configure the EditorFor template for every datatime objects in any of my models.
I'm getting this error:
\EditorTemplates\DateTime.cshtml(1): error CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named 'TextBox' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
Here's the entire code that's inside of the EditorTemplate called, DateTime.cshtml places in the EditorTemplates folder.
Any ideas?
Here's what I call in my View:
<div class="editor-label">
@Html.LabelFor(model => model.DateOfBirth)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DateOfBirth)
@Html.ValidationMessageFor(model => model.DateOfBirth)
</div>
And this is the custom EditorTemplate I made:
@Html.TextBox("", Model, new { @class = "date-selector" });
THE EDITOR IS WORKING
Basically, for every datetime object in my models, I want to add the class "date-selector" to that html element. This is for jQueryUI purposes.
What am I doing wrong?
You can create an extension method as below:
public static MvcHtmlString CalenderTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
{
return htmlHelper.TextBoxFor(expression, "{0:M/dd/yyyy}", new { @class = "datepicker text" });
}
Then use in view as below:
@Html.CalenderTextBoxFor(model => model.Employee.HireDate)