I'm working on a website that has 4 individual sections, each with their own controller. These controllers share a few models, however the model will do things slightly differently based on the controller calling it.
The route that I'd like to follow is {controller}/{model}/{id}/{action}
so I could use controller1/cars/5/edit
rather than controller1/editcar/5
.
Is there any way to have my controller understand a model+action combination and handle them with different ActionResults, or am I forced to use an ActionResult on the model name and then use a conditional to figure out what action to take?
In Ruby I could use get "/controller1/cars/:id/edit" do
. I'm just looking for something similar in MVC4.
Example routs:
/controller1/cars
- (returns a view containing all cars from controller1)
/controller1/cars/5
- (returns a view containing car with the ID 5 from controller1)
/controller1/cars/5/edit
- (returns a view to edit car with ID 5 from controller1)
/controller2/cars
- (returns a view containing all cars from controller2)
/controller2/boats
- (returns a view containing all boats from controller2)