Reputation: 985
I am working on an MVC3 app that has several forms. When I get to one form if a variable (ViewData) is true I want to check a checkbox by default but I have no idea how to do this. Any help?
Thanks,
Rhonda
Upvotes: 1
Views: 2283
Reputation: 53396
With the HtmlHelper extension :
<% Html.CheckBox("name", bool.Parse(ViewData["isChecked"])) %>
Upvotes: 2
Reputation: 3380
I would recommend using Html.CheckboxFor()
. Here's a simple example. If you have a model with a property IsSet
then you can do this:
@Html.CheckBoxFor(m => m.IsSet)
Good luck.
Upvotes: 3