maxp
maxp

Reputation: 25141

Basic ASP.NET MVC 3 Query

If i were to create a really really simple MVC3 web app, with the pages

http://localhost/home, http://localhost/b and http://localhost/c, does this mean creating three seperate controllers?

I was hoping to route all three through one controller with a seperate 'ActionResult' for each.

Thanks.

Upvotes: 2

Views: 112

Answers (2)

WooHoo
WooHoo

Reputation: 1922

Yeah you can add routes and use the same controller.

But I like my controllers to represent related work. So for example an account controller would have a login, registeration and signup. CustomerController might have list, create, edit, delete.

Upvotes: 0

Deleted
Deleted

Reputation: 4988

You can do that by adding a route for each URL to the same controller and different actions.

http://www.asp.net/mvc/tutorials/creating-custom-routes-cs

Example:

routes.MapRoute( "home", "{action}",
    new { controller = "Home", action = "Index", id = "" }); 

That will route to actions called "home" "b" and "c".

Although I wouldn't do it. I tend to always have a controller and action as it makes categorisation of concerns easier later.

Upvotes: 6

Related Questions