如何在 ASP.Net MVC 中默认设置 CheckBox [英] How to set a CheckBox by default Checked in ASP.Net MVC

查看:33
本文介绍了如何在 ASP.Net MVC 中默认设置 CheckBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 ASP.Net MVC 项目中使用 CheckBox,

I am using CheckBox in my ASP.Net MVC project,

我想设置复选框默认选中,

i want to set checkBox by default checked,

我的复选框是

@Html.CheckBoxFor(model => model.As, new { @checked = "checked" })

但它不起作用,,,,

推荐答案

在渲染视图的控制器操作中,您可以将模型的 As 属性设置为 true:

In your controller action rendering the view you could set the As property of your model to true:

model.As = true;
return View(model);

在您看来很简单:

@Html.CheckBoxFor(model => model.As);

现在由于模型的 As 属性设置为 true,CheckBoxFor 助手将生成一个选中的复选框.

Now since the As property of the model is set to true, the CheckBoxFor helper will generate a checked checkbox.

这篇关于如何在 ASP.Net MVC 中默认设置 CheckBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆