views:

19

answers:

1

hi,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  A: 

Try defining the following route before the default route:

routes.MapRoute(
    "Custom",
    "{index}",
    new { controller = "Home", action = "Detail", index = "" }
);
Darin Dimitrov
thinks, it's right.
i'm sorry, it's "thanks", not "thinks"