ASP.NET MVC 控制器动作设计 [英] ASP.NET MVC controller actions design

查看:32
本文介绍了ASP.NET MVC 控制器动作设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很喜欢 ASP.NET MVC 的工作方式.我很想在所有新的 Web 项目中实现它,但前几天我在原型中遇到了一个障碍,我真的没有找到一个好的解决方案,所以我问你,你会如何设计一个 MVC 应用程序这不符合典型的 REST 模式?例如,我正在设计的原型会有多个页面,但页面本身不一定绑定到域模型.以一个简单的注册站点为例,它可能有以下页面:

I really like the way ASP.NET MVC works. I'd love to implement it on all new web projects moving forward, but I hit a snag in a prototype the other day that I really haven't found a good solution for, so I ask you, how would you design an MVC app that doesn't fit the typical REST pattern? As an example, the prototype I was designing would have several pages, but the pages themselves aren't necessarily bound to a domain model. For example, take a simple registration site, which might have the following pages:

  • /Default.aspx
  • /Register.aspx
  • /ThankYou.aspx

有时,此类程序可能需要管理部分来处理诸如审核注册或查看数据之类的详细信息.在标准的 ASP.NET Web 应用程序中,我可能会添加以下内容

Occasionally, such a program might require an admin section to deal with such details as moderating sign ups or reviewing data. In a standard ASP.NET web app, I might add the following

  • /Admin/Default.aspx
  • /Admin/ListRegistrations.aspx
  • /Admin/ViewReports.aspx ...

在这种情况下,拥有两个控制器是否与 MVC 模式存在不可接受的偏差,例如:

Would it be an unacceptable deviation from the MVC pattern, in this case, to have two controllers such as:

  • 首页->索引
  • 首页->注册
  • 首页->谢谢
  • 管理->索引
  • Admin->ListRegistrations
  • 管理->报告

我对此感到沮丧的是,目前还没有真正可靠的子控制器和区域实现.我知道 Phil Haack 组装的Areas"原型,但它不是很成熟,坦率地说,我不确定我喜欢它的设置方式,但我真的不知道我喜欢也可以看看效果.

My frustration with this is compounded by the fact that there is no real solid implementation of subcontrollers and areas yet. I'm aware of the "Areas" prototype put together by Phil Haack, but it's not very mature, and quite frankly, I'm not sure I like the way it's setup, but I don't really know how I'd like to see that work either.

我想当我想到 MVC 时,我也倾向于想到 REST,并且让控制器操作代表页面而不是实际实体或操作并不适合我.你怎么看?

I guess when I think MVC, I tend to think REST as well, and having controller actions that represent pages rather than actual entities or actions doesn't sit right with me. What do you think?

推荐答案

您始终可以将 ASP.NET Web 窗体与 MVC 混合使用.

You can always mix ASP.NET Web Forms with MVC.

只需添加

routes.IgnoreRoute("Pages/{*path}");

到您的路由表,并将传统的 Web 表单页面添加到应用程序的 Pages 文件夹中.

to your routing table and add traditional Web form pages to Pages folder of the application.

这篇关于ASP.NET MVC 控制器动作设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆