3

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?

3
  • +1 Thats a good question, pity it took some finding, make a more careful search for the more popular applicable tags, it massively increases your chances of getting an answer in a timely fashion. Commented Dec 9, 2009 at 14:44
  • 1
    @George: Why C#? What evidence is there that that is relevent. The important tag that was missing originally was workflow-foundation. Commented Dec 9, 2009 at 15:08
  • @AnthonyWJones ASP.NET MVC is mostly done with C# - and C# allows a broader swath of developers to lay eyes on this problem that while they don't have direct MVC experience, they do have experience in the problem domain and can assist. Commented Dec 9, 2009 at 22:38

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

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; }
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.