109*_*793 3 c# view asp.net-mvc-2
我收到以下错误:
The type arguments for method 'System.Web.Mvc.Html.DisplayExtensions.DisplayFor<TModel,TValue>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TValue>>, string)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Run Code Online (Sandbox Code Playgroud)
这是我的部分观点:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyApp.Data.Person>" %>
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)<fieldset> <legend>Information</legend> <div class="display-label">ID</div> <div class="display-field"><%: Model.ID %></div><br /> <div class="display-label">Name</div> <div class="display-field"><%: Model.Name %></div><br /> <div class="display-label">DOB</div> <div class="display-field"><%: String.Format("{0:g}", Model.DOB) %></div><br /> <div class="display-label">On Alert</div> <div class="display-field"><%: Html.DisplayFor(Model.OnAlert, "FormBoolean") %></div><br /> <div class="display-label">Deactivated</div> <div class="display-field"><%: Model.Deactivated %></div><br /> </fieldset>
这是我的FormBoolean显示模板:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Boolean>" %>
<div class="formValueShort"><%= Html.Encode(Model ? "Yes" : "No") %></div>
Run Code Online (Sandbox Code Playgroud)
任何人都可以对此有所了解吗?我也试过'LabelFor'(不包括'FormBoolean'),HiddenFor,EditorFor - 都给出了同样的信息.这很奇怪,因为我已经通过我的项目使用了这些,所以我不确定为什么它会被困在这个特定的项目上.
如果我需要提供更多信息,请告诉我们!
第一个参数DisplayFor
是lambda表达式.你需要像这样打电话:
<%: Html.DisplayFor(m => m.OnAlert, "FormBoolean") %>
Run Code Online (Sandbox Code Playgroud)