7

I'm about to create quite simple website which will contain several static pages (they will never change) and one dynamic change (let's call it news). I'was wondering whether it's possible to use MVC here without having to create controllers and views for these "static" pages. Isn't that just too much overhead?

Is there a way to make MVC simply route incoming requests to valid documents without actually having to create controller?

2 Answers 2

11

Just put your static content in a separate directory and link to it there. ASP.NET will simply serve up the static content as normal when the path is to a actual file. I created a static folder in my Content folder, but you could put it anywhere. The files could even live in the root of the site.

   +-Content
     +-images
     +-static
       +-about.html
       +-info.html
     +-styles
       +-site.css
       +-themes
        ...
Sign up to request clarification or add additional context in comments.

1 Comment

does that also applies if i have 'static' aspx file? Cause I'm having some problems with that.. (thanks for reply!)
0

For "static" aspx files, you would need to wire up a route (or use the default catch all) to something like:

public SomeAction ActionResult(string pageName)
{
    return View(pageName);
}

And that should let someone make views in the appropriate folder and then have them be added and or executed on the fly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.