我試圖定義一個Boolean.cshtml使用下面的代碼與EditorFor使用:如何爲布爾創建編輯器模板? (.EditorFor <>)
@{
var o = ViewData.ModelMetadata;
}
<div class="editor-for">
@Html.CheckBox(o.PropertyName,
ViewData.Model,
new { @class="tickbox-single-line" })
</div>
不幸的是,型號爲NULL,我得到以下非描述性錯誤:
CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named 'CheckBox' 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.
看完這個我試過如下:
@Html.CheckBox(o.PropertyName,
ViewData.Model ?? false,
new { @class="tickbox-single-line" })
但我得到完全相同的錯誤。查看代碼很簡單:
@Html.EditorFor(m => m.RememberMe)
我在做什麼錯誤的Boolean.cshtml?
我被你的第二個片段混淆。 @model bool做了什麼? –
@LuisFerrao好吧,它只是一個布爾編輯器模板的通常演示文稿 –
這並沒有告訴我它做了什麼,但我想在這一點上,我應該只是RTFM。無論如何,這個工作,所以我會把它標記爲答案。 –