开发者

MVC3 Check a checkbox on page load

开发者 https://www.devze.com 2023-03-08 11:07 出处:网络
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

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"])) %>
0

精彩评论

暂无评论...
验证码 换一张
取 消