C# .NET MVC Call an action from another controller
Posted
by Brian
on Stack Overflow
See other posts from Stack Overflow
or by Brian
Published on 2010-05-24T20:14:05Z
Indexed on
2010/05/24
20:21 UTC
Read the original article
Hit count: 423
I have two different objects: contracts, and task orders. My requirements specify that in order to view the Details for either object, the Url should be "http://.../Contract/Details" or "http://.../TaskOrder/Details" depending on which type. They are both very similar and the details pages are almost identical, so I made a class that can either be a contract or a task order, and has a variable "objectTypeID" that says which type it is. I wrote the action "Details" in the task order controller, but now I want to call that from the contract controller instead of recopying the code.
So is there any way to have the url still say ".../Contract/Details" but call the action in the TaskOrder controller instead? I tried using
TaskOrderController TOController = new TaskOrderController();
TOController.Details(id);
This would have worked except that I can't use the HttpContext.Session anymore, which I used several times in the action.
© Stack Overflow or respective owner