我的ASP MVC 4应用程序存在问题
这是我已知的错误:
参数字典包含非可空类型'System.Int32'参数'page'的空条目,方法'System.Web.Mvc.ActionResult Index(Int32,Int32,Int32)'
这是我的RouteConfig.cs
:
routes.MapRoute(
name: "AppareilRoute",
url: "Appareil/page/{page}/{pageSize}/{triCol}",
defaults: new { controller = "Appareil", action = "Index", page = "{page}", pageSize = "{pageSize}", triCol = "{triCol}" }
);
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
我的电话:
@Html.RouteLink("Appareils", "AppareilRoute", new { page=0, pageSize=50, triCol=0 })
控制器接收始终为空值。
我对这个错误感到非常失望,我尝试了很多东西,但都没有用...... 有人可以帮我吗?谢谢。
答案 0 :(得分:1)
您需要将整数值作为默认值放在路线中:
routes.MapRoute(
name: "AppareilRoute",
url: "Appareil/page/{page}/{pageSize}/{triCol}",
defaults: new { controller = "Appareil", action = "Index", page = 0, pageSize = 50, triCol = 0 }
);