ASP.NET MVC 中的工作流

发布于 2024-08-15 20:55:32 字数 373 浏览 4 评论 0原文

作为学习练习,我想将现有的 Flash 应用程序迁移到 ASP.NET MVC。它有大约 20 种形式,虽然大部分是线性的,但根据用户决策或返回的数据存在一定程度的替代流程。

有人能指出控制器如何处理这个问题的正确方向吗?我不希望我的观点必须弄清楚下一步该走向何方。

更新

我想我可能不理解构建这个的正确方法。我认为每个控制器负责应用程序的不同部分,并有一个主控制器负责工作流程。

如果这不是我应该采取的方法,那么最好的方法是什么?

更新 2

ASP.NET MVC 2 中的区域会负责应用程序的此部分吗?我真的不喜欢在一个控制器中执行太多操作的想法......

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

Could anyone point me in the right direction of how a controller would handle this? I don't want my views to have to figure out where they go to next.

Update

I think I may not be understanding the correct way of building this. I saw each controller as taking care of a different section of the app, and having a main controller being responsible for workflow.

If this is not the approach I should be taking, what is the best way of doing this?

Update 2

Would Areas in ASP.NET MVC 2 take care of this sectioning of the app? I really don't like the idea of having too many actions in one controller...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

隱形的亼 2024-08-22 20:55:32

一般来说:

控制器通常是处理逻辑上连贯的应用程序块的操作的集合(因此您经常看到 UserController / OrderController 等)。

MVC 应用程序应该使用 PRG ( post-redirect-get ) 构建,这意味着每个表单将有 2 个操作,一个将显示表单,第二个具有相同的名称,但用 [AcceptPost] 装饰,它将处理表单并根据结果将用户重定向到适当的位置。

了解其工作原理并迁移应用程序的最简单方法是将每个表单建模为没有逻辑的简单 dto,为每个表单和 2 个操作构建一个视图。

一旦逻辑在控制器中工作,您可能希望将其迁移到可以注入控制器的某种形式的服务中。

专门针对您的工作流程:

每个工作流程可能应该有自己的控制器。使用某种形式的状态模式(取决于工作流程的复杂性)对它们进行建模可能很有用,并提供每个状态转换的结果,您的控制器可以将其转换为重定向到工作流程中的下一步。

In general:

Controllers are usually a collection of actions that deal with a logically coherent chunk of the application ( hence why you often see UserController / OrderController etc etc ).

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

The simplest way to learn how this works and migrate your app over is model each form as a simple dto with no logic, build a view for each form and 2 actions.

Once you have the logic working in the controller, you may want to migrate it out into some form of service that can be injected into the controller.

Specifically for your workflows:

Each workflow should probably have it's own controller. It may be useful to model them using some form of state pattern ( depending on the complexity of the workflow ), and providing a result from each state transition that your controller can translate into a redirect to the next step in the workflow.

梦里°也失望 2024-08-22 20:55:32

当表单发布到控制器操作时,控制器操作将决定如何处理发布的结果以及接下来渲染或重定向哪个视图:

[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");
}

When a form posts to a controller action it is the controller action to decide what to do with the posted results and which view to render next or redirect:

[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");
}
风吹雪碎 2024-08-22 20:55:32

我正在努力解决同样的问题(使用 Windows Workflow Foundation 和 ASP.NET MVC),并且我在博客中介绍了它 此处

也许您会发现它有帮助,抱歉推送我自己的链接

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

Maybe you'll find it helpful, sorry for pushing my own link

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文