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的更多相关文章

  1. [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 ...

  2. Understanding ROS Services and Parameters

    service是nodes之间通信的一种方式,允许nodes send a request and recieve a response. rosservice rosparam roservice ...

  3. 9.Parameters

    1.Optional and Named Parameters calls these methods can optionally not specify some of the arguments ...

  4. Oracle Net Listener Parameters (listener.ora)(转)

    12/20 7 Oracle Net Listener Parameters (listener.ora) This chapter provides a complete listing of th ...

  5. ROS学习手记 - 5 理解ROS中的基本概念_Services and Parameters

    上一节完成了对nodes, Topic的理解,再深入一步: Services and Parameters 我不理解为何 ROS wiki 要把service与parameter放在一起介绍, 很想分 ...

  6. H.264视频的RTP荷载格式

    Status of This Memo This document specifies an Internet standards track protocol for the   Internet ...

  7. ROS教程

    Learning ROS 学习ROS Depending on your learning style and preferences, you can take two approaches to ...

  8. 深入理解typescript的Functions

    Functions Introduction # Functions are the fundamental building block of any application in JavaScri ...

  9. 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 ...

随机推荐

  1. mysql 常用总结

    centos7 安装mysql 数据库安装参考:http://www.cnblogs.com/longrui/p/6071581.htmlhttps://www.cnblogs.com/yoursou ...

  2. C语言实现单链表的遍历,逆序,插入,删除

    单链表的遍历,逆序,插入,删除 #include<stdio.h> #include<stdlib.h> #include <string.h> #define b ...

  3. centOS升级部分功能后,不能进入桌面(桌面)

    在Linux中安装nginx,安装过程中需要安装c++等一部分环境,装完后,莫名奇妙的centos就不能进入桌面了,命令窗口可以进去. 网上查了查资料,说是升级了一部分功能,和内核有冲突.需要更新下系 ...

  4. AngularJs学习——常用表单指令练习

    一.知识点 ng-show.ng-hide.ng-if(控制元素显示隐藏,区别在于ng-hide是是否显示隐藏元素,而ng-if是是否移除元素): ng-src.ng-class(为元素添加路径和cl ...

  5. 最大公倍数_Greatest Common Divisor

    计算最大公倍数 Static int gcd( int a, int b) { int t; while( b>0) { t = b; b = a % b; a = t; } return a; ...

  6. 【BZOJ3998】弦论 [SAM]

    弦论 Time Limit: 10 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description 对于一个给定长度为N的字符串,求它的第 ...

  7. 「6月雅礼集训 2017 Day11」delight

    [题目大意] 有$n$天,每天能吃饭.睡觉.什么事也不干 每天吃饭的愉悦值为$e_i$,睡觉的愉悦值为$s_i$,什么都不干愉悦值为0. 要求每连续$k$天都要有至少$E$天吃饭,$S$天睡觉. 求最 ...

  8. 【CODEVS】3546 矩阵链乘法

    [算法]区间DP [题解] 注意先输出右括号后输出左括号. f[i][i+x-1]=min(f[i][i+x-1],f[i][j]+f[j+1][i+x-1]+p[i]*p[j+1]*p[i+x]) ...

  9. UIImagePickerController---iOS-Apple苹果官方文档翻译

    //本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址  //转载请注明出处--本文永久链接:http://www.cnblogs.com ...

  10. 特征工程(Feature Engineering)

    一.什么是特征工程? "Feature engineering is the process of transforming raw data into features that bett ...