ASP.Net MVC 3 EditorTemplate for DateTime Fields Error

Banford picture Banford · Feb 14, 2011 · Viewed 13.7k times · Source

This code was converted from some ASP.Net MVC 2 code in this tutorial:
MVC 2 Editor Template with DateTime

It is a custom EditorTemplate for DateTime fields stored as 'EditorTemplates/DateTime.cshtml'.

@Model DateTime?
@Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty), new { @class = "datePicker" })

However I get the following error when using @Html.EditorFor(model => model.NewAbsence.StartDate):

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.

I've seen some similar posts on here which mention casting the parameter of the EditorFor method, however I cannot seem to get this to work in my example.

Could someone please point out what I will need to change in my code. Thanks.

Answer

Darin Dimitrov picture Darin Dimitrov · Feb 14, 2011

Actually it's @model with lowercase m:

@model DateTime?
 ^

instead of:

@Model DateTime?