3
,我發現了以下錯誤:Html.DisplayFor編譯錯誤 - 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.
這裏是我的局部視圖:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyApp.Data.Person>" %>
<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>
任何人都可以對此有所瞭解嗎?我也嘗試過'LabelFor'(不包括'FormBoolean'),HiddenFor,EditorFor - 都給出了相同的信息。這很奇怪,因爲我已經通過我的項目使用過這些東西,所以我不確定它爲什麼卡在這個特定的項目上。
讓我知道是否需要提供更多信息!
啊!很簡單!這是漫長的一天!非常感謝。當時間到了的時候,我會將你的回答標記爲正確:) – 109221793 2012-01-04 22:20:21