0

I have an MVC application and the url looks like this;

/celebritypage/celebrityname=Elma Fudd

What I'd like is to only have;

/celebritypage/Elma Fudd

Is this possible within routing?

3
  • This article from Scott Gu should provide all the information you need: weblogs.asp.net/scottgu/archive/2007/12/03/… Commented Mar 1, 2012 at 23:22
  • Are the spaces intentional? They are non-standard for URLs. Also, the path with an equals is also pretty non-standard. Are you asking about routing a celebrity in general, or specifically about using spaces? Commented Mar 2, 2012 at 0:07
  • the spaces are irrelevant. they will be %20, i just wanted to illistrate what i was after Commented Mar 2, 2012 at 0:36

1 Answer 1

4

Sure, something like this should work:

routes.MapRoute(
    "RouteName",
    "celebritypage/{name}",
    new { controller = "celebritypage", action = "celebrityname" }
);

Then make sure your controller action is ready for the parameter:

//inside celebritypage Controller

public ActionResult celebrityname(string name) {
    //code
    return View("ViewName");
}
Sign up to request clarification or add additional context in comments.

Comments

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.