I think there's some confusion on the way routing works here - lemme see if I can help.
If you want to create a way to handle paging for a list, you can do that by creating a new route rule:
[controller]/list/[page]
and make sure this is placed on top of the other rules since the first valid rule for any URL will be applied (hope this makes sense) - in other words there is an order of precedence here.
OK, that said, if you try to pass in a value of "page" as an argument, there has to be an argument named "page" on the action so we can set that argument when we "method.Invoke()". This invocation is explicit - not done by ordering.
It's all well and good that i can add [page] to the url. but I WHAT my urls to look like /Products/List?page=x but i also want the url /Products/List to go to page 1 by default.
Obviously i could check RouteData and if "page" isn't found set it to 1, but this means i can't parameterise my methods with
page, and i'll have to do that for each controller which does paging.
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Extra defaults bug
Dec 21, 2007 09:05 PM|LINK
Hi,
Steps to reproduce:
The first route in Global.asax.cs should look like this...
RouteTable.Routes.Add( new Route
{
Url = "[controller]/[action]/[id]",
Defaults = new { action = "Index", id = (string)null, page = 1 },
RouteHandler = typeof( MvcRouteHandler )
} );
Simply adding page = 1 (or anything which isn't matched in the Url) breaks all the links which match this route.
MVC Routes bug
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: Extra defaults bug
Dec 24, 2007 03:22 AM|LINK
could someone confirm this as a bug?
If the instructions aren't clear let me know and I'll try to clarify.
robconery
Participant
852 Points
195 Posts
Re: Extra defaults bug
Dec 24, 2007 06:11 PM|LINK
I think there's some confusion on the way routing works here - lemme see if I can help.
If you want to create a way to handle paging for a list, you can do that by creating a new route rule:
[controller]/list/[page]
and make sure this is placed on top of the other rules since the first valid rule for any URL will be applied (hope this makes sense) - in other words there is an order of precedence here.
OK, that said, if you try to pass in a value of "page" as an argument, there has to be an argument named "page" on the action so we can set that argument when we "method.Invoke()". This invocation is explicit - not done by ordering.
Does this help?
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: Extra defaults bug
Dec 24, 2007 09:47 PM|LINK
Sorry, Not really.
It's all well and good that i can add [page] to the url. but I WHAT my urls to look like /Products/List?page=x but i also want the url /Products/List to go to page 1 by default.
Obviously i could check RouteData and if "page" isn't found set it to 1, but this means i can't parameterise my methods with page, and i'll have to do that for each controller which does paging.
robconery
Participant
852 Points
195 Posts
Re: Extra defaults bug
Dec 24, 2007 10:46 PM|LINK
To be sure I know what the issue is, let me repeat it back.
You're defining in your route some defaults, with id being null, the action being "Index", and page=1. With your route, you're specifying:
RouteTable.Routes.Add( new Route
{
Url = "[controller]/[action]/[id]",
Defaults = new { action = "Index", id = (string)null, page = 1 },
RouteHandler = typeof( MvcRouteHandler )
} );
And the issue you're seeing is that if an action has an argument called "page", it's not being set to 1 - correct?
If I'm getting closer here - did you define a route the ties "page" into the Url? Like this:
RouteTable.Routes.Add( new Route
{
Url = "[controller]/[action]/[page]",
Defaults = new { action = "List", page = 1 },
RouteHandler = typeof( MvcRouteHandler )
} );
You have to be explicit with respect to args, their name, and the Routes. Am I getting closer? :):)
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: Extra defaults bug
Dec 25, 2007 02:14 AM|LINK
see topic http://forums.asp.net/t/1197244.aspx for an example of this bug.
---
Oh, and merry christmas.
robconery
Participant
852 Points
195 Posts
Re: Extra defaults bug
Dec 25, 2007 04:50 AM|LINK
You too :)