如何在 ASP.NET MVC 1.0 中实现区域以与 ASP.NET MVC 2.0 最大程度兼容

发布于 2024-07-30 02:42:28 字数 1213 浏览 3 评论 0 原文

直到昨天 ASP.NET MVC 预览版发布之前,我一直非常需要像“区域”这样的功能,但不知道它叫什么才能找到它。

预览版将“区域”描述为:

区域 - 提供划分区域的方法 大型 Web 应用程序分成多个 项目,每个项目都可以 相对孤立地发展起来。 这 帮助开发人员管理复杂性 构建一个大型应用程序 提供一种分组相关的方法 控制器和视图。

就我而言,我正在构建一个在线商店作为应用程序的一部分。 我想使用 /store/products//store/checkout 等控制器对 /store/ 下的所有内容进行分区。

ASP.NET 2.0 区域功能似乎正是我想要的,但我还不能证明将其用于生产应用程序是合理的(尽管它非常诱人!)。

我注意到 Phil 在 11 月份写了一篇关于“分组控制器”的文章 - 实际上标题为“ASP.NET MVC 中的领域'

如果有人使用过其中任何一种方法,或者最好是熟悉这两种方法的人,我真的会很感兴趣。

我想尽快将我的商店逻辑移至一个单独的“区域” - 但无法决定是尝试使用 Phil 的 11 月解决方案还是冒险在预览版中实施它? 我认为即使我的一些代码也需要更改 - 我创建的 RESTful URL 不需要更改,所以我现在倾向于尝试“分组控制器”方法。 有人也试过吗?

http://haacked.com/archive/2008/11/ 04/areas-in-aspnetmvc.aspx

MSDN 区域文档:http://msdn.microsoft.com/en-us/library/ee307987(VS.100).aspx

Until the preview release yesterday of ASP.NET MVC I had been desperately needing a feature like 'areas' but not known what it was called to be able to find it.

The preview release describes 'areas' as :

Areas - provide a means of dividing a
large web application into multiple
projects, each of which can be
developed in relative isolation. This
helps developers manage the complexity
of building a large application by
providing a way to group related
controllers and views.

In my case I am building an online store as one part of the application. I'd like to partition everything under /store/ with controllers like /store/products/ and /store/checkout.

The ASP.NET 2.0 areas feature seems to be exactly what I want, but I cant yet justify moving to it for a production application (although its very tempting!).

I noticed that Phil had an article about 'grouping controllers' way back in November - actually titled 'Areas in ASP.NET MVC'

Would really be interested if anybody has used either approach - or prefarably someone familiar with both.

I'd like to move my store logic into a separate 'area' as soon as possible - but can't decide whether to try to use Phil's November solution or just risk implementing it with the preview release? I assume that even some of my code would need to change - the RESTful URLS I would have created would not need to change so I'm leaning towards trying the 'grouping controllers' method for now. Anybody tried either?

http://haacked.com/archive/2008/11/04/areas-in-aspnetmvc.aspx

MSDN areas documentation: http://msdn.microsoft.com/en-us/library/ee307987(VS.100).aspx

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

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

发布评论

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

评论(2

⊕婉儿 2024-08-06 02:42:28

我在我目前正在从事的项目中的 MVC 1.0 中使用 Phil 的早期区域原型(您链接到的那个)。 它的工作方式似乎与 MVC 2.0 领域类似,并且到目前为止对我来说工作得很好。 您需要进行一些调整才能使通用视图正常工作< /a> 不过。

和您一样,我无法证明使用生产代码的预览版本是合理的...希望 2.0 发布后重构不会有太多工作。

I'm using Phil's earlier areas prototype (the one you linked to) in MVC 1.0 in the project I'm currently working on. It seems to work similar to MVC 2.0 areas, and it's working fine so far for me. There is a tweak you need to make to get generic views working though.

Like you, I can't justify using the preview release for production code... hopefully it won't be too much work to refactor later when 2.0 is released.

万人眼中万个我 2024-08-06 02:42:28

因为 Asp.net MVC 2.0 仍处于 Preview 1 阶段,并且没有上线许可证。 因此,您不能在实际应用中使用它。 解决此问题的最简单方法是创建自定义控制器工厂和控制器工厂。 自定义控制器,例如本文

此外,您必须专注于创建类似区域的应用程序的自定义路由。 请查看

请阅读有关 Asp.net MVC 2

PS 的更多信息。 我想和你一样。 控制器/视图结构不足以满足大型或中型 Web 应用程序的需要。

Because Asp.net MVC 2.0 is still in Preview 1 phrase and it doesn't has a go live license. So, you can't use it in real-world application. The easiest way to solve this problem is creating custom controller factory & custom controller like this article.

Moreover, you must focus on custom routing for crating area-like application. Please look at this.

Please read this for more info about Asp.net MVC 2

PS. I think like you. The controller/view structure isn't enough for large-scale or middle-scale web application.

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