Workflows in ASP.NET MVC

As a training exercise, I want to migrate an existing flash application to ASP.NET MVC. It has about 20 forms, and although it is mostly linear, there is some degree of alternative flows based on user decisions or returned data.

Can someone point me in the right direction of how the controller will handle this? I do not want my views to figure out where they are going next.

Update

I think that perhaps I do not understand the correct way to build this. I saw how each controller took care of another section of the application, and the main controller was responsible for the workflow.

If this is not the approach I should take, what is the best way to do this?

Update 2

Areas in ASP.NET MVC 2 take care of this separation of applications? I really don't like the idea of โ€‹โ€‹having too many actions in one controller ...

+4
source share
3 answers

Generally:

Controllers are usually a set of actions that relate to a logically sequential fragment of an application (therefore, why do you often see UserController / OrderController, etc. etc.).

MVC applications must be created using PRG (post-redirect-get), which means that you will have 2 actions for each form, one of which will display the form and the second with the same name, but decorated with [AcceptPost], which will process the form and redirect the user to the appropriate place based on the result.

The easiest way to find out how it works and transfer the application is to model each form as a simple dto without logic, build a view for each form and 2 actions.

When you have logic running in the controller, you can transfer it to one form or another of service that can be entered into the controller.

In particular, for your workflows:

Each workflow must have its own controller. It may be useful to simulate them using a state template (depending on the complexity of the workflow) and providing a result from each state transition that your controller can take to redirect to the next step in the workflow.

+3
source

When the form is submitted to the controller action, this is the controller action to decide what to do with the published results and which view to display or redirect later:

[AcceptVerbs(HttpVerbs.Post)] public ActionResult HandleFormSubmission(FormCollection col) { // do something with posted data // redirect to /someOtherController/someOtherAction // which could show some other form return RedirectToAction("someOtherAction", "someOtherController"); } 
+1
source

I was struggling with the same problem (using the Windows Workflow Foundation with ASP.NET MVC) and I wrote about it here

You may find this helpful, sorry for clicking my own link

+1
source

All Articles