背景分析

在控制器方法中的一个参数允许为null值:public ActionResult GetByCategory(int? categoryId = null)
当把这里的categoryId传给服务类方法时 var products = service.LoadProductsByCategory((categoryId),报错。

解决方法

这里的categoryId默认是是null,
而服务类方法所需要的类型是int,
需要强转一下: var products = service.LoadProductsByCategory((int)categoryId);

报错:无法从int?转换为int的更多相关文章

  1. sql servel 报错:将 expression 转换为数据类型 int 时出现算术溢出错误。

    执行sql语句:SELECT   AVG( DATEDIFF(s,s.CreatedDate,s.SendDate)  ) AS submitTime FROM dbo.SmsSend AS s    ...

  2. 【报错】"The constructor Notification(int, CharSequence, long) is deprecated

    Notification的构造方法 Notification(int, CharSequence, long) 在API11之后就淘汰了,之后的API需要用Notification.Builder() ...

  3. C#中int? 转换为 int 型

    用 “ var a= zongfen.Score;”

  4. scala中计算的的一个小问题,超出Int.maxValue时不会报错

    如果小于Int.max时他不会报错 def sumcount(str:String): Int ={ val ints = for(c <- str)yield { println(c.asIn ...

  5. double转换为int以及浮点型相加损失精度问题

    最近在做支付相关模块的业务,数据库字段却使用的是double类型,其实也行,只要计算不在sql语句中进行,也是没有问题的. 预先的类属性设置的是Double类型,自己算的时候发现小数相加会出现损失精度 ...

  6. C#中(int)、int.Parse()、int.TryParse()和Convert.ToInt32()的区别

    转自:http://www.cnblogs.com/leolis/p/3968943.html 在编程过程中,数据转换是经常要用到的,C#中数据转换的方法很多,拿将目标对象转换为 整型(int)来讲, ...

  7. C#中(int)、int.Parse()、int.TryParse()和Convert.ToInt32()的区别 <转>

    作者:Statmoon 出处:http://leolis.cnblogs.com/   在编程过程中,数据转换是经常要用到的,C#中数据转换的方法很多,拿将目标对象转换为整型(int)来讲,有四种方法 ...

  8. (int)、int.Parse()、int.TryParse()和Convert.ToInt32()的区别

    C#中(int).int.Parse().int.TryParse()和Convert.ToInt32()的区别   原文链接:http://www.cnblogs.com/leolis/p/3968 ...

  9. 关于JAVA中Byte数据类型二进制赋值运算报错问题

    自从JDK7更新之后,新增了二进制变量的表示,支持将整数类型用二进制来表示,用0b开头: 例如: byte b= (byte) 0b1000_0001; short s = (short) 0b100 ...

随机推荐

  1. (四)MyBatis关系映射

    第一节:一对一关系实现 需要实现一对一的关系,首先我们有两张表,t-addree和t_student. CREATE TABLE `t_address` ( `id` ) NOT NULL AUTO_ ...

  2. Icon.png pngcrush caught libpng error:Read

    [问题处理]Icon.png pngcrush caught libpng error:Read Error 遇到问题 在项目Archive时,遇到 Icon.png pngcrush caught ...

  3. 20165203迭代和JDB测试

    1.使用C(n,m)=C(n-1,m-1)+C(n-1,m)公式进行递归编程实现求组合数C(m,n)的功能 public class C { public static void main(Strin ...

  4. 利用Octopress在github pages上搭建个人博客

    利用Octopress在github pages上搭建个人博客 SEP 29TH, 2013 在GitHub Pages上用Octopress搭建博客,需要安装ruby环境.git环境等.本人在Fed ...

  5. CentOS 7不能联网解决办法

    在使用 Ubuntu 一段时间之后想体验一下 CentOS,就去下载了 CentOS 7 安装到了虚拟机里面,结果发现不能联网,一直提示Cannot find a valid baseurl for ...

  6. Cannot read property ‘msie’ of undefined错误原因以及解决方案

    最近把一个项目的jQuery升级到最新版,发现有些页面报错Cannot read property ‘msie’ of undefined.上jQuery网站上搜了一下,$.browser这个api从 ...

  7. 【Java】java.lang.NullPointerException的两个原因

    自己写程序时出现过 java.lang.NullPointerException错误的一些原因 (1)自己建立了一个数组,但每个数组元素没单独初始化(单独new一个新对象). (2)在进行if (ar ...

  8. Bootstrap进阶七:LESS语法详解

    1.变量 2.混合 3.带参数混合 4.模式匹配和导引表达式 5.嵌套规则 6.运算 7.Color函数 8.Math函数 9.命名空间 10.作用域 11.注释 12.Importing 13.字符 ...

  9. Python 中的函数

    学了 Python 中的数据类型,语句,接下来就来说一下 Python 中的函数,函数是结构化编程的核心.我们使用函数可以增加程序的可读性.自定义函数时使用关键字def 函数由多条语句组成.在定义函数 ...

  10. Initramfs 原理和实践

    Linux系统启动时使用initramfs (initram file system), initramfs可以在启动早期提供一个用户态环境,借助它可以完成一些内核在启动阶段不易完成的工作.当然ini ...