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 ...
随机推荐
- JavaScript中进制之间的转换
JavaScript中进制之间的转换 //十进制转其他 var x = 100; alert(x); alert(x.toString(2)); //转2进制 alert(x.toString(8)) ...
- best code #54 div 2 A 水
A problem of sorting Accepts: 443 Submissions: 1696 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- Saddle Point ZOJ - 3955 题意题
Chiaki has an n × m matrix A. Rows are numbered from 1 to n from top to bottom and columns are numbe ...
- idea 多模块引用
roma-server 引用common-utils的类,所以在roma-server 的pom中配置 <dependency> <groupId>org.springfram ...
- mysql 中 group_concat()用法
基本语法:group_concat([DISTINCT] 要连接的字段 [Order BY 排序字段 ASC/DESC] [Separator '分隔符']) 初始数据: ...
- asp.net 文件上传,大文件上传。
新建一个asp.net页面,在工具栏里拖入 FileUpload 上传控件.一个按钮 Button ! ! ! 进入Button事件 //----------------------- ...
- JNLP Slave connection error解决办法
Replace in jnlp-file <argument>-workDir</argument> <argument /> with <argume ...
- 「6月雅礼集训 2017 Day11」tree
[题目大意] 给出一棵带权树,有两类点,一类黑点,一类白点. 求切断黑点和白点间路径的最小代价. $n \leq 10^5$ [题解] 直接最小割能过..但是树形dp明显更好写 设$f_{x,0/1/ ...
- 【洛谷 P3809】 【模板】后缀排序
题目链接 先占个坑,以后再补. \(SA\)的总结肯定是要写的. 等理解地深入一点再补. #include <cstdio> #include <cstring> const ...
- 【洛谷 P1419】 寻找段落(二分答案,单调队列)
题目链接 开始还以为是尺取.发现行不通. 一看标签二分答案,恍然大悟. 二分一个\(mid\)(实数),把数列里每个数减去\(mid\),然后求前缀和,在用单调队列维护\(sum[i-t\text{~ ...