0

I have the following controller:

public ActionResult Search(string Name, int? Friend, int? Page)

It works if I use this url localhost/users/search/name but these don't localhost/users/search/name/1 and localhost/users/search/name/1/1

2
  • What doesn't work about it? You don't get the right parameter values, or the method is never called? Either way, it would help if you showed how you're mapping your routes. Commented Apr 2, 2010 at 5:53
  • I have no custom routes set up, when I add the additional parameters I get a 404 error. Commented Apr 2, 2010 at 6:10

1 Answer 1

3

You have to define additional route:

routes.MapRoute(
                "UsersSearch",                                              // Route name
                "users/search/{name}/{friend}/{page}",                           // URL with parameters
                new { controller = "Users", action = "Search" }  // Parameter defaults
            );


routes.MapRoute(
                "UsersSearch",                                              // Route name
                "users/search/{name}/{friend}",                           // URL with parameters
                new { controller = "Users", action = "Search" }  // Parameter defaults
            );
Sign up to request clarification or add additional context in comments.

1 Comment

So by default it accepts one parameter, and if you want additional parameters you have to map them specifically?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.