tags:

views:

45

answers:

3

Is there a specific design practice for MVC type sites that need to have a lot of non-model related pages? I mean, it seems very silly to make a controller action for every single page; Yet at the same time, that seems to be the only way to realistically do it and adhere to standards. Is there any documentation or examples available for things like this?

When I speak of non-model pages, I mean things that are just display; Static information that you might use a standard HTML website layout for. But it has to be intermingled with other parts of the site that do require models and validation/etc.

+2  A: 

Create a folder for your static content, and put in an ignore route for those pages. This causes those pages to be passed through directly to IIS for immediate display.

routes.IgnoreRoute("StaticPages/{*path}"); 

You can also load static HTML content into an existing View. This preserves your ability to work with dynamic content in the same page.

Robert Harvey
But then those pages cannot contain any model data from a controller if it is ever needed, right?
Stacey
See my edit....
Robert Harvey
So suppose I want to have some friendly urls to these paths; Is there any way to incorporate that?
Stacey
You would need to involve the routing engine to do that. But if you are serving up static pages, you can just write a simple controller or controller/view combination that returns the HTML from the file, rather than an actual view.
Robert Harvey
A: 

I don't think it sounds silly at all to make an action for every page. That's just how MVC works.

You can ignore some routes, as Robert Harvey suggests, but then you'll have the *.html extension on your static pages but not your internal ones, and you'll be unable to use the Url. and Html. helper methods for linking to MVC actions.

I think you should just go with the flow.

Gabe Moothart
A: 

Another alternative was suggested for common static files such as help pages which is based more on a naming convention, but would allow for some flexibility in layout control in the view:

ASP.Net MVC Routing Strategy for Static Content

Turnkey