views:

353

answers:

1

I have a state machine workflow which contains a number of states. Each state has an event driven activity that handles an external event. When that event fires, I'd like to either redirect the request to a different Controller Action or a View.

What is the best way to redirect to a different view or controller action when an event is fired in state machine workflow?

+1  A: 

You can just use the RedirectToAction method:
http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction.aspx

Once your workflow determines what action needs to be executed, call that method and the browser will be redirected and control moved to that action. On the other hand, if you just need to present a specific view, you can just use the controller's View method and pass in the name of the view you want to show:
http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.view.aspx

Joel Martinez
Thank you all know commented and answered this question. I earned a "tumble weed" badge for this question and thought nobody was going to answer it.Is it possible for to call RedirectToAction method from an external event of the workflow when the workflow is run from an action of a controller?For instance, in my action, I'd have:ActionResult DoSomething(int id){MyExternalEventService.RaiseEvent();WorkflowRuntimeHandle.RunWorkflow();//here I could query StateMachineWorkflowInstance and redirect//based on the current state or I could let the event redirect;}
Cullen Tsering
Well, it depends ... the result of RedirectToAction must be returned from the action method. So if you can extract that value from the workflow and return it then sure ... however, i'd suggest just running your workflow, then examining the state and deciding your action in the action method based on that
Joel Martinez