0

guy, i have a page in my asp.net mvc website. the Route configuration:

        public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{index}", // URL with parameters
            new { controller = "Home", action = "Detail", index = "" } // Parameter defaults
        );
    }

the Controller code:

        public ActionResult Detail(string index)
    {
        string[,] List = new string[,] { {"1", "first item"}, {"3", "middle item"}, {"5", "last item"}};
        ViewData["Message"] = "no results.";

        if (!string.IsNullOrEmpty(index))
        {
            for (int i = 0; i <= List.GetUpperBound(0); i++)
            {
                if (List[i, 0] == index)
                {
                    ViewData["Message"] = List[i, 1];
                }
            }
        }

        return View();
    }

and i want user to visit http://www.domain.com/5 redirect Action Detail with parameter 5.

how to support it?

thinks.

1 Answer 1

6

Try defining the following route before the default route:

routes.MapRoute(
    "Custom",
    "{index}",
    new { controller = "Home", action = "Detail", index = "" }
);
Sign up to request clarification or add additional context in comments.

1 Comment

@Darin Dimitrov I asked a similar question here: stackoverflow.com/questions/23237336/… would you please check it

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.