简体   繁体   English

ASP MVC 4路由错误

[英]ASP MVC 4 Routes error

I have a problem with my ASP MVC 4 application 我的ASP MVC 4应用程序有问题

here is my known error: 这是我的已知错误:

The parameters dictionary contains a null entry for parameter 'page' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(Int32, Int32, Int32)' 参数字典包含方法'System.Web.Mvc.ActionResult Index(Int32,Int32,Int32)'的非空类型'System.Int32'的参数'page'的空条目。

Here is my RouteConfig.cs : 这是我的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 }
        );

My call: 我的电话:

@Html.RouteLink("Appareils", "AppareilRoute", new { page=0, pageSize=50, triCol=0 })

The controller receive always nulls values. 控制器始终接收空值。

I'm so disappointing with this error, I have tried many things, but none works... 我对这个错误感到非常失望,我尝试了很多事情,但没有一个...
Anyone could help me here? 有人可以在这里帮助我吗? Thank you. 谢谢。

You need to put integer values as your defaults in the route: 您需要在路由中将整数值作为默认值:

routes.MapRoute(
        name: "AppareilRoute",
        url: "Appareil/page/{page}/{pageSize}/{triCol}",
        defaults: new { controller = "Appareil", action = "Index", page = 0, pageSize = 50, triCol = 0 }
    );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM