tags:

views:

71

answers:

2

Lets say I'm converting a whole bunch of content pages - dumb HTML - over to MVC model.

I'd want to stick all the plain HTML files in a directory and 'find' them based on a controller.

This kind of appears to be what the 'HomeController' in the standard ASP.NET-MVC is doing, but I have to explicitly add each page.

[HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewData["Title"] = "Home Page";
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult About()
        {
            ViewData["Title"] = "About Page";

            return View();
        }

        public ActionResult About2()
        {
            ViewData["Title"] = "About Page 2";

            return View();
        }
    }

I added an About2.aspx page in the 'Home' directory, and had to add an About2 method into the HomeController to enable the URL http://localhost:51234/Home/About2.

But lets say I have 50 HTML pages and I want to find them based on the URL.

How could I achieve that?

+1  A: 

Update the route handler in global.asax to ignore routing for your static pages. To make this easier I would put them in a separate directory.

routes.IgnoreRoute("static/myfile.htm");
tvanfosson
but i want something like routes.IgnoreRoute("static/*");can i do that?
Simon_Weaver
Any luck coming up with an answer to that?
justSteve
A: 

Along time ago in a galaxy far far away I submitting a patch to Castle monorail to implement the DefaultAction functionality the reason for this was to acomplish almost exactly the same thing you are wanting to do. The difference being the designers still needed access to dynamic data like login names and such in the views. It looks like the ConventionController in the MVC Contrib supports the same functionality.

Basicly it allows you to have a method that is called when no other matching method is found. This method can look at the request and determine what view to render. As I stated the beauty of this solution is that a designer does not need a controller action method coded for every page they want to show the user, but they still can get access to available data you provide to them through the model.

Mike Glenn