Hi,
I've got the following route:
routes.MapRoute(
"Search",
"Search.aspx/l-{lID}/t-{tID}/p-{pID}/s-{sID}",
new {
controller = "Search",
action = "Search",
lID = "",
tID = "",
pID = "",
sID = "" },
new { lID = @"\d{0,}",
tID = @"\d{0,}",
pID = @"\d{0,}",
sID = @"\d{0,}" }
);
Which works fine providing my url is http://localhost:1234/Search.aspx/l-1/t-1/p-1/s-1 but I want some of these parameters to be empty so a url may look like: http://localhost:1234/Search.aspx/l-/t-/p-1/s- however when this happens I keep getting 404 errors.
Does anyone know how I can make this route work so I can have empty values?
Update:
Following the advice I upgraded the project to MVC 2 however the problem still occurs. My route now looks like:
routes.MapRoute(
"Search",
"Search.aspx/l-{lID}/t-{tID}/p-{pID}/s-{sID}",
new
{
controller = "Search",
action = "Search",
lID = UrlParameter.Optional,
tID = UrlParameter.Optional,
pID = UrlParameter.Optional,
sID = UrlParameter.Optional
},
new
{
lID = @"\d{0,}",
tID = @"\d{0,}",
pID = @"\d{0,}",
sID = @"\d{0,}" }
);
I'm still getting 404's when trying to view the view with empty values in.
Also another issue that has come up since moving to version 2 is that the RedirectToRoute can't seem to find the route. I get
No route in the route table matches the supplied values.
error message. My code looks like:
return RedirectToRoute(
"Search",
new {
lID = lID,
tID = tID,
pID = pID,
sID = sID
}
);
Again any help would be much appreciated.
Thanks