0

i am trying to create strongly type checkbox but this not working properly and
checkbox not show is checked but flag is true in model please suggest me code:-

 @Html.CheckBoxFor(model => model.Active, new { @checked =true})
Dip Girase
  • 439
  • 1
  • 7
  • 18
  • 2
    Possible duplicate of [How to set a CheckBox by default Checked in ASP.Net MVC](https://stackoverflow.com/questions/16435448/how-to-set-a-checkbox-by-default-checked-in-asp-net-mvc) – Esko Apr 05 '19 at 08:57
  • @Esko i am not set default checkbox ,i want to set checkBox by my get database value – Dip Girase Apr 05 '19 at 09:19
  • 1
    @DipGirase set the value in the model Controller-side _before_ you get to the View. The code `@Html.CheckBoxFor(model => model. Active);` will then represent that value. Also, `Active` must be a `bool` type. (this is as per the solution @Esko suggested) – scgough Apr 05 '19 at 09:25

1 Answers1

0

Use a EditorFor

@Html.EditorFor(model => model.Active, new { Value = model.Active})

or

@Html.EditorFor(model => model.Active)

As other users have said: Set the value of Active on the model Controller-side before you get to the View and also, Active must be a boolean type. (this is as per the solution @Esko suggested)

Dimitri
  • 1,185
  • 2
  • 15
  • 37