bool?
public class GuestResponse
{
[Required(ErrorMessage = "Please enter your name")]
public string Name { get; set; }
[Required(ErrorMessage = "Please enter your email address")]
[RegularExpression(".+\\@.+\\..+", ErrorMessage = "Please enter a valid email address")]
public string Email { get; set; }
[Required(ErrorMessage = "Please enter your phone number")]
public string Phone { get; set; }
[Required(ErrorMessage = "Please specify whether you'll attend")]
public bool? WillAttend { get; set; }
}
Tip As noted earlier, I used a nullable bool for the WillAttend property. I did this so that I could apply the
Required validation attribute. If I had used a regular bool, the value I received through model binding could be only true
or false, and I wouldn’t be able to tell if the user had selected a value. A nullable bool has three possible values: true,
false, and null. The null value will be used if the user hasn’t selected a value, and this causes the Required attribute
to report a validation error. This is a nice example of how the MVC Framework elegantly blends C# features with HTML and
HTTP.
5.1下测试,如果不定义为 bool? ,如果未选择,绑定后值为false,但验证也未通过,实际接收的值为“”值。
bool?的更多相关文章
- iOS关于通知传值Bool类型的注意点
比如: [[NSNotificationCenter defaultCenter] postNotificationName:@"Notification_Name" object ...
- Context值和bool开关
Context值和bool开关的相关内容 Context值分为2种 系统默认的context值 服务的context值 Context值的作用 主要是防止有未知文件进入目录文件之中(如将病毒拷贝到 ...
- stm32 usb error : identifier "bool" is undefined
.\usb\USB\usb_pwr.h(54): error: #20: identifier "bool" is undefinedusb\USB\usb_pwr.h(54): ...
- 2.4嵌套多重if else 的闰年判断以及bool变量的用法
#include<stdio.h> #include<stdbool.h> int main() { int year; bool leap; //把leap定义为bool , ...
- bool型变量下标的时候javascript是不能允许的
jother编码是我最开始想写的内容,原因有两点:1.原理比较简单,不需要太多关于算法的知识.2.比较有趣,是在对javascript有了很深的理解之后催生的产物.如果你只需要知道jother编码和解 ...
- .NET Core中合并Expression<Func<T,bool>>的正确姿势
这是在昨天的 .NET Core 迁移中遇到的问题,之前在 .NET Framework 中是这样合并 Expression<Func<T,bool>> 的: public s ...
- Elasticsearch查询——布尔查询Bool Query
Elasticsearch在2.x版本的时候把filter查询给摘掉了,因此在query dsl里面已经找不到filter query了.其实es并没有完全抛弃filter query,而是它的设计与 ...
- and or bool and a or b 原理解释
python 中的and从左到右计算表达式,若所有值均为真,则返回最后一个值,若存在假,返回第一个假值. or也是从左到有计算表达式,返回第一个为真的值. 代码如下: IDLE 1.2.4>&g ...
- Predicate<T>与Func<T, bool>泛型委托
引用别人的: static void Main(string[] args) { List<string> l = new List<string>(); l.Add(&quo ...
- Elasticsearch判断多列存在、bool条件组合查询示例
and符号判断多列存在:{ "filter": { "and": [ { "exists": { ...
随机推荐
- 如何停止Android Monkey脚本
如何停止Android Monkey脚本 最近用monkey来包apk的性能测试,发现一旦monkey跑起来以后,即使将数据线和PC断开,monkey脚本还是会继续运行下去.结果找到了一个办法去停止它 ...
- AutoCompleteTextView与TextWatcher的结合
/******************************************************************************************** * au ...
- ORG 07C00H的意思
简单说来,该指令用来修正该指令以后出现的(变量/标志的)内存地址,也就是说如果有ORG 0x12345h,那么在该指令以后的变量的地址将被修正为0x12345+old_addr.对于DOS中的COM文 ...
- kafka迁移与扩容
参考官网site: http://kafka.apache.org/documentation.html#basic_ops_cluster_expansion https://cwiki.apach ...
- POJ 1847 Tram【Floyd】
题意:给出n个站点,每个站点都有铁路通向其他站点 如果当前要走得路恰好是该站点的开关指向的铁路,则不用扳开关,否则要手动扳动开关,给出起点和终点,问最少需要扳动多少次开关 输入的第一行是n,start ...
- Asp.Net验证码3
using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System. ...
- Linux删除文件后空间没有释放
.COMMAND默认以9个字符长度显示的命令名称.可使用+c参数指定显示的宽度,若+c后跟的参数为零,则显示命令的全名.PID:进程的ID号.PPID父进程的IP号,默认不显示,当使用-R参数可打开. ...
- MySQL Database on Azure - 利用PowerShell快速创建使用数据库服务
如果您的应用需要通过脚本快速创建一个或多个MySQL数据库,MySQL Database on Azure目前开放了对于PowerShell的支持,可以帮助您快速利用自动化脚本进行数据库服务的创建.管 ...
- struts2运行机制
struts2是web应用中一个常用的mvc框架,下面探讨一下其内部运行机制: 1.从客服端浏览器输入的url后,客服端通过http协议发送一个请求到服务器(tomcat),Tomcat收到这个请求之 ...
- Android 高仿腾讯旗下app的 皮肤加载技术
http://www.cnblogs.com/punkisnotdead/p/4968851.html 以前写的这篇文章 可以高仿出 知乎 新浪微博等 绝大多数app的换肤技术,但是遗漏了腾讯的效果, ...