Understanding Optional and Compulsory Parameters
If the MVC Framework cannot find a value for a reference type parameter (such as a string or object), the action
method will still be called, but using a null value for that parameter. If a value cannot be found for a value type parameter (such
as int or double), then an exception will be thrown, and the action method will not be called. Here is another way to think
about it:
Value-type parameters are compulsory. To make them optional, either specify a default value (see the next section) or
change the parameter type to a nullable type (such as int? or DateTime?), so the MVC Framework can pass
null if no value is available.
值类型可以指定默认值,或指定值类型可以为null。
public ActionResoult Index(int ? Age,string Name)
or
public ActionResoult Index(int Age = 18 , string Name = "jack")
应验证数据是否为null。
如果值无法转换为指定类型,ModelState将置为false。
Reference-type parameters are optional. To make them compulsory (to ensure that a non-null value is passed), add
some code to the top of the action method to reject null values. For example, if the value equals null, throw an
ArgumentNullException.
引用类型应验证数据是否为null。
Understanding Optional and Compulsory Parameters的更多相关文章
- [Angular2 Router] Optional Route Query Parameters - The queryParams Directive and the Query Parameters Observable
In this tutorial we are going to learn how to use the Angular 2 router to pass optional query parame ...
- Understanding ROS Services and Parameters
service是nodes之间通信的一种方式,允许nodes send a request and recieve a response. rosservice rosparam roservice ...
- 9.Parameters
1.Optional and Named Parameters calls these methods can optionally not specify some of the arguments ...
- Oracle Net Listener Parameters (listener.ora)(转)
12/20 7 Oracle Net Listener Parameters (listener.ora) This chapter provides a complete listing of th ...
- ROS学习手记 - 5 理解ROS中的基本概念_Services and Parameters
上一节完成了对nodes, Topic的理解,再深入一步: Services and Parameters 我不理解为何 ROS wiki 要把service与parameter放在一起介绍, 很想分 ...
- H.264视频的RTP荷载格式
Status of This Memo This document specifies an Internet standards track protocol for the Internet ...
- ROS教程
Learning ROS 学习ROS Depending on your learning style and preferences, you can take two approaches to ...
- 深入理解typescript的Functions
Functions Introduction # Functions are the fundamental building block of any application in JavaScri ...
- One SQL to Rule Them All – an Efficient and Syntactically Idiomatic Approach to Management of Streams and Tables(中英双语)
文章标题 One SQL to Rule Them All – an Efficient and Syntactically Idiomatic Approach to Management of S ...
随机推荐
- caffe中的Accuracy+softmaxWithLoss
转:http://blog.csdn.net/tina_ttl/article/details/51556984 今天才偶然发现,caffe在计算Accuravy时,利用的是最后一个全链接层的输出(不 ...
- Codeforces Round #326 (Div. 2) B Duff in Love 简单数论 姿势涨
B. Duff in Love time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- frame外弹出,刷新父页面
//刷新父页面 function reflashParent() { var id = parent.tabbar.getActiveTab(); id = id.replace('tab','mai ...
- UVA 10214 Trees in a Wood
https://vjudge.net/problem/UVA-10214 题意:你站在原点,每个坐标位置有一棵高度相同的树,问能看到多少棵树 ans=Σ gcd(x,y)=1 欧拉函数搞搞 #incl ...
- JavaScript之typedof,instanceof,Array.isArray()
typedof value检测对象类型. value instanceof Array检测a对象是否由b对象类型 Array.isArray(value)在两个框架中判断是否为数组类型.
- [Luogu 3973] TJOI2015 线性代数
[Luogu 3973] TJOI2015 线性代数 这竟然是一道最小割模型. 据说是最大权闭合子图. 先把矩阵式子推出来. 然后,套路建模就好. #include <algorithm> ...
- Linux SSH 无密码登录
1. ssh-keygen -t rsa 2. scp root@ip:/root/.ssh/id_rsa.pub ./id2 3. cat id2 >> authtorized_keys ...
- Achain 钱包部署
官网 GIT: [ Achain_linux ] 基础环境 OS: CentOS, Ubuntu Achain: 官网 [ release 最新版本 ] 安装 Achain 钱包 下载 CentOS ...
- 关于cocos2d-x 中 CCEditBox 的输入位置和IOS虚拟键盘位置不重合的bug
这个文章的名字起的实在是有点长,主要是怕说不清楚. 在IOS上,输入时,我看到过的比较少,就两种,如附件两张图.一个是虚拟键盘的输入框完全是在CCEditBox上,另一张虚拟键盘的输入区域是紧挨着键盘 ...
- javascript执行上下文学习一
原文: http://web.jobbole.com/84044/ http://blog.csdn.net/github_34514750/article/details/52901781 1.三种 ...