2

I have a web application made with ASP.NET MVC 5. In this application I have a view which display a list of information.

In this list I display a boolean information with @Html.DisplayFor(modelItem => item.valide). So a CheckBox is displayed and it's checked and disabled.

How can I do to remove the disabled="disabled" from the CheckBoxes ?

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
Adrien
  • 2,866
  • 4
  • 23
  • 46
  • 1
    DisplayFor is providing readonly representation and EditorFor should be used if you want to be able to change the value. – mybrave Sep 15 '17 at 08:47

2 Answers2

6

try

@Html.EditorFor(modelItem => item.valide)

or

@Html.CheckBoxFor(modelItem => item.valide)

instead

Dan Nguyen
  • 1,308
  • 6
  • 17
0

If you want to have an enable checkbox with DisplayFor then you need to have a template.

Create a DisplayTemplates folder under Shared folder an add a partial view to it and name it something for example (_myTemplate) and then paste the following code to it:

@model bool
@Html.CheckBoxFor(c => c)

Then you can have an enable CheckBox when using DisplayFor helper (just don't forget to specify the template that you've created):

@Html.DisplayFor(c => c.Valide, "_myTemplate")
Salah Akbari
  • 39,330
  • 10
  • 79
  • 109