Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC controller actions design

I really like the way ASP.NET MVC works. I'd love to implement it on all new web projects moving forward, but I hit a snag in a prototype the other day that I really haven't found a good solution for, so I ask you, how would you design an MVC app that doesn't fit the typical REST pattern? As an example, the prototype I was designing would have several pages, but the pages themselves aren't necessarily bound to a domain model. For example, take a simple registration site, which might have the following pages:

  • /Default.aspx
  • /Register.aspx
  • /ThankYou.aspx

Occasionally, such a program might require an admin section to deal with such details as moderating sign ups or reviewing data. In a standard ASP.NET web app, I might add the following

  • /Admin/Default.aspx
  • /Admin/ListRegistrations.aspx
  • /Admin/ViewReports.aspx ...

Would it be an unacceptable deviation from the MVC pattern, in this case, to have two controllers such as:

  • Home->Index
  • Home->Register
  • Home->ThankYou
  • Admin->Index
  • Admin->ListRegistrations
  • Admin->Reports

My frustration with this is compounded by the fact that there is no real solid implementation of subcontrollers and areas yet. I'm aware of the "Areas" prototype put together by Phil Haack, but it's not very mature, and quite frankly, I'm not sure I like the way it's setup, but I don't really know how I'd like to see that work either.

I guess when I think MVC, I tend to think REST as well, and having controller actions that represent pages rather than actual entities or actions doesn't sit right with me. What do you think?

like image 558
Chris Avatar asked Feb 27 '09 14:02

Chris


People also ask

What are controllers and actions in MVC?

A controller action returns something called an action result. An action result is what a controller action returns in response to a browser request. The ASP.NET MVC framework supports several types of action results including: ViewResult - Represents HTML and markup.

How do I add actions to my controller?

Adding an Action to a Controller You add a new action to a controller by adding a new method to the controller. For example, the controller in Listing 1 contains an action named Index() and an action named SayHello(). Both methods are exposed as actions.

What are action methods in ASP.NET MVC?

ASP.NET MVC Action Methods are responsible to execute requests and generate responses to it. By default, it generates a response in the form of ActionResult. Actions typically have a one-to-one mapping with user interactions.


1 Answers

You can always mix ASP.NET Web Forms with MVC.

Just add

routes.IgnoreRoute("Pages/{*path}");

to your routing table and add traditional Web form pages to Pages folder of the application.

like image 107
mmx Avatar answered Sep 23 '22 23:09

mmx