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": { ...
随机推荐
- You can't specify target table 'charge' for update in FROM clause
mysql中不能这么用. (等待mysql升级吧)错误提示就是说,不能先select出同一表中的某些值,再update这个表(在同一语句中) 替 换方 案: create table tmp as s ...
- [转载]java的几种对象(PO,VO,DAO,BO,POJO)解释
原文地址:java的几种对象(PO,VO,DAO,BO,POJO)解释作者:munandong 一.PO:persistant object 持久对象,可以看成是与数据库中的表相映射的java对象.最 ...
- C#操作文件
c# 操作txt文件 # 操作txt文件 c#创建文本 private const string FILE_NAME = "ErroLog.txt"; public static ...
- 在blade中定义一个可以被模版使用的变量
laravel的blade中的数据一般由控制器传入,但是有没有什么办法临时在blade模版中创建并且被blade所使用吗? 答案是肯定的,不过语法稍微复杂一点 {{-- */$variableAvai ...
- [转] POJ DP问题
列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 13 ...
- 配置域名服务器报错named[822]: dns_rdata_fromtext /etc/bind/db.asertest.com mail not a valid number
问题描述: 为了配置邮件服务器,更改了相关域名,改完后,重启bind9报错 Mar 17 14:39:39 DnsServer2 named[822]: dns_rdata_fromtext: /et ...
- java之IO
IO流主要用于硬板.内存.键盘等处理设备上得数据操作 一.IO流分类 java.io包中定义了多个流类型(类或抽象类)来实现输入/输出功能,可以从不同角度对其分类: 1.按数据流的方向不同分为:输入流 ...
- [ ] 字符组(Character Classes) (转)
[]能够匹配所包含的一系列字符中的任意一个.需要注意的是,[]虽然能匹配其中的任意一个字符,但匹配的结果只能是一个字符,不是多个. 例如[abc]表示字符“a”或“b”或“c”. []支持用连字符“- ...
- 【英语】Bingo口语笔记(20) - i长短音
短音有个ei的音,多练习下 长音是咦拉长
- ASIHTTPRequest详解
ASIHTTPRequest对CFNetwork API进行了封装,并且使用起来非常简单,用Objective-C编写,可以很好的应用在Mac OS X系统和iOS平台的应用程序中.ASIHTTPRe ...