在 MVC 中创建向导表单以及如何管理视图和控制器文件夹

发布于 2024-09-16 18:36:47 字数 332 浏览 9 评论 0原文

我需要制作一个包含 3 个步骤的表单向导。每个步骤都可以单独保存在数据库中。步骤将是输入有关公司的信息,然后输入其出版物,最后输入其预订。

我应该将所有逻辑放在一个控制器中还是放在不同的控制器中?我的第一个想法是在一个控制器中,因为这都是关于管理一家公司的,但问题是我将在控制器和 View 文件夹中拥有大量代码,我将拥有大约 20 个网页。

有没有办法将子文件夹放在 View\Companies\ 文件夹中,这样我就可以拥有 View\Compangies\Publications。这样,我可以将每个主题的网页分开。

或者你如何处理?有没有更好的方法来正确处理向导表单?

亚历克斯

i need to make a form wizard of 3 steps. Each steps can be saved in the database separatly. The steps will be to enter information about an Company, then his Publications and finally his Reservations.

Should i put all the logics in one controller or different controllers? My first thought would be in one controller since this is all about managing a company but the problem with that is i will have a lot of code in the controller and in the View folder, i will have like 20 webpages.

Is there a way to put subfolders in the View\Companies\ folder so i could have View\Compangies\Publications. That way, i can separate the web pages for each theme.

Or how do you manage that? Is there a better way to handle properly Wizard Forms?

alex

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

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

发布评论

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

评论(1

-柠檬树下少年和吉他 2024-09-23 18:36:47

取决于型号。如果您的出版物是它们自己的实体,并且它们最终存储(在数据库中)在它们自己的表中,那么它们拥有自己的控制器可能是正确的方法。与预订相同。如果您将这两个存储为公司实体的一部分,那么它们最好保留在公司控制器中。但在我看来,他们应该分开。

关于控制器操作之间的重定向,您始终可以使用 RedirectToAction() 在同一控制器内进行重定向。

您还可以使用 MVC Futures 项目及其 RedirectToAction() 扩展,您还可以在不同控制器之间重定向。

FWIW,我认为如果您正在编辑具有自己的属性等的出版物,它属于自己的实体,因此它们需要拥有自己的模型、控制器和随后的视图(在视图根目录下的单独视图文件夹中) 。

更新:

如下所示的路线有什么问题:

为具有 {companyId} 的公司创建出版物

/Publication/Create/{companyId}

编辑具有 id {publicationId} 的出版物并为具有 {companyId} 的公司

/Publication/Edit/{companyId}/{publicationId}

或如果出版物 ID 是唯一的,无论公司如何

/Publication/Edit/{publicationId}

Depends on the Model. If your Publications are their own entity and they eventually get stored (in DB) in their own table, it might be the proper way for them to have their own controller. The same with Reservations. If you store both of those as a part of the Company entity then it might be better for them to stay in Company controller. But it seems to me that they ought to be separate.

With regards to redirection between controller actions you can always use RedirectToAction() to redirect inside the same controller.

You can also use MVC Futures project and their RedirectToAction() extensions with which you can also redirect between different controllers.

FWIW, I think that if you are editing Publication that has its own properties etc. it belongs in their own Entity and as such they need to have their own Model, Controller and subsequently Views (in a separate View folder at the root of Views).

UPDATE:

What's wrong with a route looking like this:

Creating a publication for a company with {companyId}

/Publication/Create/{companyId}

or

Editing a publication with an id {publicationId} and for a company with {companyId}

/Publication/Edit/{companyId}/{publicationId}

or if publication ID's are unique regardless of the company

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