Asp.Net Mvc复选框为默认值? [英] Asp.Net Mvc Checkboxfor default value?

查看:207
本文介绍了Asp.Net Mvc复选框为默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

模型

[DefaultValue(true)]
public bool IsActive { get; set; }

检视

@Html.CheckBoxFor(model => model.IsActive)

html输出这是我的预期

html output and that is my expected

<input data-val="true" data-val-required="Yayında alanı boş bırakılmamalıdır!" id="IsActive" name="IsActive" type="checkbox" value="true" class="valid">

但不选中复选框。我不明白为什么?

but checkbox is not checked. I cant understand why? What am I missing?

感谢。

推荐答案

a href =http://msdn.microsoft.com/en-us/library/system.componentmodel.defaultvalueattribute.aspx =nofollow> MSDN

Per the MSDN



DefaultValueAttribute不会导致成员自动使用属性的值初始化。您必须在代码中设置初始值。

A DefaultValueAttribute will not cause a member to be automatically initialized with the attribute's value. You must set the initial value in your code.


这篇关于Asp.Net Mvc复选框为默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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