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": { ...
随机推荐
- nodetree中 前面复选框禁用插件
nodetree中 前面复选框的去掉插件 extendTreeCheck.js /** * tree方法扩展 * 作者:小雪转中雪 */ $.extend($.fn.tree.methods, { / ...
- 中文web font技术及方案
我们在日常需求中,经常会碰到视觉设计师对某个中文字体效果非常坚持的情况,因为页面是否高大上,字体选择是很重要的一个因素,选择合适的字体可以让页面更优雅.面对这种问题,我们通常以下方式来进行设计还原: ...
- The Guide To Understanding mysqlreport
The Guide To Understanding mysqlreport This guide to understanding mysqlreport explains everything t ...
- *ecsho 的商品详细页面上获取该商品的一级分类ID及NAME
1.打开goods.php并找到 $smarty->assign('goods', $goods); 在它上面增加以下代码 $cat_arr = get_parent_cats($goods[' ...
- [转载] FFMpeg的码率控制
mediaxyz是一位研究ffmpeg有三年的高人了,这几天一直在折腾ffmpeg中的x264,就是不知道该如何控制码率,主要是参数太多,也不知道该如何设置,在google上search了一下,这方面 ...
- java UncaughtExceptionHandler 处理线程意外中止
本文转自:http://peirenlei.iteye.com/blog/305079 Thread的run方法是不抛出任何检查型异常(checked exception)的,但是它自身却可能因为一个 ...
- 502 Bad Gateway nginx 解决
打开 /usr/local/php/etc/php-fpm.conf 调大以下两个参数(根据服务器实际情况,过大也不行) <value name=”max_children”>5120&l ...
- Informatica9.6.1在Linux Red Hat 5.8上安装遇到的有关问题整理_4
4.创建Integration Service后无法启动 1)错误日志: 2)解决办法: 进入Repository Service的属性页面,将其运行模式改成Normal.
- hdu 4643(计算几何)
题意:容易理解 分析:切换的地点为两个基站所在直线的中垂线与两座城市所在直线的交点. 代码实现: #include <cstdio> #include <cmath> #inc ...
- ylb:表的结构的修改和基本约束
ylbtech-SQL Server:SQL Server-表的结构的修改和基本约束 SQL Server 表的结构的修改和基本约束. 1,表的结构的修改和基本约束返回顶部 use master go ...