views:

65

answers:

3

Might not be a very consequential question, but...

I have a bunch of mostly-static pages: Contact, About, Terms of Use, and about 7-8 more.

Should each of these have their own controllers, or should I just have one action for each?

Thanks in advance.

+1  A: 

There is no harm in having one controller with an action for each page. I would likely make a HomeController with an ActionResult and corresponding aspx view for Contact, About, Terms of Use, etc... For this simple case, if you want more control over the url or there is a logical grouping of the controllers that makes sense then you may want to break it into 2 or more controllers.

Nunery
+1  A: 

Just consider each item individually. If you think that there is even the slightest chance that the action/view could be required to be more than just static data then break it up now or else you will have to worry about breaking links in the future that your customers/visitors/search engines have saved/indexed and now you will need to possibly maintain some redirects etc.

If you are sure that it will never change (ha who says never) then use one controller with many actions/views. Eg:

http://yoursite.com/home/contact
http://yoursite.com/home/terms
http://yoursite.com/home/about
etc...

This will save your project from a lot of clutter for very basic data assuming that you will have a lot of other code. If the majority of you code is just these pages though you should break it up because there is nothing to clutter up anyways.

Kelsey
+1  A: 

The recommended use case in ASP.NET MVC is to create a separate controller per model and separate action methods on the controller per concern, i.e. action each for edit, create, retrieve and delete for example.

However, in this use case since you mentioned that all you have are static pages it seems the job can be done via the use of one controller and separate action methods corresponding to each views. It can be implemented as so,

public HomeController : Controller
{
    public ActionResult About()
    {
        return View();
    }

    public ActionResult TermsOfUse()
    {
        return View();
    }

    public ActionResult Contact()
    {
        return View();
    }

    // etc ........
}

HomeController is chosen here since it comes by default in ASP.NET MVC projects and is wired to the default route in Global.asax.cs file.

Bikal Gurung