I am working开发者_如何学JAVA 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
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.
With the HtmlHelper extension :
<% Html.CheckBox("name", bool.Parse(ViewData["isChecked"])) %>
精彩评论