2
Vote

InvalidOperationException for the following routes

description

YABE is currently throwing an InvalidOperationException for the following routes.
 
http://localhost/aboutme/ http://localhost/resume/ http://localhost/project/   The parameters dictionary does not contain a valid value of type 'System.Int32' for parameter 'year'. To make a parameter optional its type should either be a reference type or a Nullable type

comments

volkanuzun wrote Sep 21, 2008 at 4:14 AM

what i did to fix this:

the problem is {year} is matching with the routes mentioned above, so i changed the routing table and a regular expression, to make sure there is 4 digit number for year, here is my fixed route:

routes.Add(new Route("{year}", new MvcRouteHandler())
        {
            Constraints = new RouteValueDictionary(new{year=@"\d4"}),
            Defaults = new RouteValueDictionary(new
            {
                controller = "Posts",
                action = "ListYear",
                year = ""
            })

            });

        routes.Add(new Route("{year}/{month}", new MvcRouteHandler())
        {
            Constraints = new RouteValueDictionary(new { year = @"\d4", month = @"0[1-9]|1[012]" }),
            Defaults = new RouteValueDictionary(new
            {
                controller = "Posts",
                action = "ListMonth",
                year = "",
                month = ""
            }),
        });

        routes.Add(new Route("{year}/{month}/{day}", new MvcRouteHandler())
        {
            Constraints = new RouteValueDictionary(new { year = @"\d4", month = @"0[1-9]|1[012]", day = @"0[1-9]|[12][0-9]|3[01]" }),
            Defaults = new RouteValueDictionary(new
            {
                controller = "Posts",
                action = "ListDay",
                year = "",
                month = "",
                day = ""
            }),
        });

        routes.Add(new Route("{year}/{month}/{day}/{title}", new MvcRouteHandler())
        {
            Constraints = new RouteValueDictionary(new { year = @"\d4", month = @"0[1-9]|1[012]", day = @"0[1-9]|[12][0-9]|3[01]" }),
            Defaults = new RouteValueDictionary(new
            {
                controller = "Posts",
                action = "Single",
                year = "",
                month = "",
                day = "",
                title = ""
            }),
        });

now, i need a controller for aboutme, for resume and project . i couldnt figure out how i can match all these with controller :)
still studying mvc

wrote Feb 14, 2013 at 12:16 AM