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 lay开发者_如何学运维out for. But it has to be intermingled with other parts of the site that do require models and validation/etc.
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.
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.
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
精彩评论