1

I'm trying to do the following with ASP.Net MVC 3:

I have a lot of "flat pages", which are basically html documents with no dot.net code attached.

I want to be able to request these pages through routed URLs, but I do not want to manually add each url to the routes.

So my question is: Is it possible to define a default route, which uses the same controller / action, but returns a view based on the URL requested ?

e.g. /home/about and /profile would use the views /home/about.cshtml and /profile.cshtml but both would use the same controller and action, which pretty much just goes:

return View();

The reason: I'm doing all the pages of the site, which require dot.net code. However another person is doing all the "flat pages" (informative pages, etc.).

I want him to be able to add new pages, by just adding a cshtml file (like he would with webforms creating aspx files, with no code-behind)

This is necessary because I'd otherwise have to edit global.asax each and everytime he adds a page, which is quite often.

If this is not possible, I'll have to stick with webforms, which I really don't want to :-(

1 Answer 1

4

You can make an action that takes as a parameter the name of the View; Something like this:

public ActionResult StaticPage(string viewName)
{
    return View(viewName);
}

Then define a route so the viewName isn't a parameter but instead is part of the URL:

"/Static/{viewName}"
Sign up to request clarification or add additional context in comments.

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.