Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I got a pretty basic ASP.NET MVC (1) routing qeustion but I couldn't find an answer by now.

I want to call an action method which has three parameters but I'm running into an 404 when I call it with more than one parameter.

Route looks like this (I removed all other routes but the default one):

routes.MapRoute(
   "Test",
   "{id}/{page}/{lineend}",
   new { controller = "Basic", action = "Test" },
   new { id = @"\d+", page = @"\d+" }
);

The method looks like this:

[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Test(int? id, int? page, string lineend)
{
    // some code here
    return new ViewResult();
}

This is what happens:

http://localhost:55462/Basic/Test/

works

http://localhost:55462/Basic/Test/1

works

http://localhost:55462/Basic/Test/1/2

gives a 404

http://localhost:55462/Basic/Test/1/2/3

gives a 404

Removing the constraints or changing the method signature to (int, int, string) has the same effect. In the first and second case the application complains about a null parameter, the other cases lead to a 404.

I know this issue has to be pretty basic but I just don't get it.

Thanks for your help!

share|improve this question
add comment

2 Answers

It will be something like this:

routes.MapRoute(
   "Test",
   "{id}/{page}/{*lineend}",
   new { controller = "Basic", action = "Test" },
   new { id = @"\d+", page = @"\d+" }
);

It is catch-all parameter. In action you have to split string using '/'

share|improve this answer
add comment

I foud it out myself. (And I hope it is correct that I add it as a separate answer.)

As expected the answer is quite simple. With the routing configuration above you need to leave out the controller name in the URL so this works:

http://localhost:55462/Test/1/2/3
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.