tags:

views:

67

answers:

1

I have created an MVC application that dynamically routes actions and controllers based on user data, so that there are no standard actions, but dynamically named actions.

In order to route the controller and action correctly, every route must go through a centralized Index which determines if the user has gone to a valid System in this case. i.e.

http://mysite.com/Systems/SystemName/RenameSystem 

...where SystemName is the dynamic system name and RenameSystem is the action.

Once a system has been routed correctly to the RenameSystem controller, the user is prompted with a textbox that allows them to change the system name. When submit is clicked, the form is routed back to my original Index Controller

public ActionResult Index(string systemName, string action)

instead of the standard

public ActionResult RenameSystem(string systemName)

I have placed in logic to determine if the RequestType is a POST or a GET. If the RequestType is a POST, the logic deviates and can capture the Form data contained in the request object.

My question is, how can I take that Form data, which contains my systemName field and route it so that I don't need to throw data into a switch statement. i.e. I DO NOT want to do this:

switch case(action)
{  
      case "RenameSystem":
      return RenameSystem(Request.Form["systemName"]);
}

and that I can dynamically POST to the standard:

public ActionResult RenameSystem(string systemName)

...simply by impersonating the calling View.

Simply put I would like to be able to take the action, RenameSystem and call it so that my systemName will automatically fall into the systemName parameter of RenameSystem.

Is this possible or are there any other choices on how to achieve this?

Thanks, George

+2  A: 

Try creating a ControllerActionInvoker and calling InvokeAction with your current ControllerContext.

SLaks
How do I get my ControllerContext?
George
Use the `ControllerContext` property of the controller.
SLaks
Worked like a charm! Thanks!
George