views:

39

answers:

2

I make Views/About/Index.aspx and Views/Faq/Index.aspx + Controllers/AboutController.cs and Controllers/FaqController.cs controllers for these purposes.

I want to have one controller Controllers/DefaultController.cs + Views/About.aspx and Views/Faq.aspx in the root, for example.

How to set it up?

A: 

No matter what, your *.aspx files for the Views should stay in the Views/{Name}/{PageName}.aspx style.

If you want a URL like http://localhost/About, you set up a default route in Global.asax.cs to point to the proper Action.

Justin Niessner
A: 

You can do something like this:

 private static readonly string[] StaticPages = 
                                   {
                                       "FaQ", "Help"
                                   };

    /// <summary>
    /// Registers the routes.
    /// </summary>
    /// <param name="routes">The routes.</param>
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute("StaticPages",
            "{id}", // url
            new { controller = "StaticPages", action = "Show" }, // defaults
            new { id = String.Join("|", StaticPages) }); // constraints


        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }); // Parameter defaults
    }
Sly
What code will have the controller in this case?
alex
For all controllers you will have "Default" route to work. For static pages like FAQ, Help you will create StaticPages controller, with appropriate actions.
Sly
Well done! Clarification. Views placed in the Views\Shared folder.
alex