此代码是从本教程中的一些 ASP.Net MVC 2 代码转换而来的:
MVC 2 Editor Template with DateTime
它是存储为“EditorTemplates/DateTime.cshtml”的 DateTime 字段的自定义 EditorTemplate。
@Model DateTime?
@Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty), new { @class = "datePicker" })
但是,使用时出现以下错误@Html.EditorFor(model => model.NewAbsence.StartDate)
:
CS1973:“System.Web.Mvc.HtmlHelper”没有名为“TextBox”的适用方法,但似乎具有该名称的扩展方法。扩展方法不能动态调度。考虑强制转换动态参数或在没有扩展方法语法的情况下调用扩展方法。
我在这里看到了一些类似的帖子,其中提到了转换 EditorFor 方法的参数,但是我似乎无法在我的示例中使用它。
有人可以指出我需要在我的代码中更改什么。谢谢。