Disable checkbox in mvc3

I am trying to disable the check box, but I get an error message and cannot understand what I'm doing wrong. My code is

@Html.CheckBox("", ViewData.TemplateInfo.FormattedModelValue, new { @disabled = true } ) 

as far as I can judge, judging by other explanations of how to disable the checkbox should work. However, I get this error:

CS1928: 'System.Web.Mvc.HtmlHelper' does not contain a CheckBox definition and the best overload method 'System.Web.Mvc.Html.InputExtensions.CheckBox (System.Web.Mvc.HtmlHelper, string, bool, object)' has some invalid arguments

Any ideas? Thanks.

+7
source share
1 answer

The CheckBox helper expects a boolean value as the second parameter. Try it like this:

 @Html.CheckBox( "", bool.Parse((string)ViewData.TemplateInfo.FormattedModelValue), new { disabled = "disabled" } ) 

or if it is a strongly typed editor template for boolean :

 @model bool @Html.CheckBox("", Model, new { disabled = "disabled" }) 
+10
source

All Articles