Ciel
Ciel

Reputation: 17782

Design Practices - Several Pages with ASP.NET MVC

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.

Upvotes: 2

Views: 204

Answers (3)

Turnkey
Turnkey

Reputation: 9416

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

Upvotes: 0

Gabe Moothart
Gabe Moothart

Reputation: 32112

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.

Upvotes: 0

Robert Harvey
Robert Harvey

Reputation: 180908

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.

Upvotes: 2

Related Questions