.NET MVC 项目的结构
我正在建立一个新项目,并希望获得一些有关它的提示,以便从一开始就可以完成它。
简而言之,这是我的项目:
将会有一些关于/信息页面:关于我们、联系方式、如何...然后创建一个 AboutController 是一个好的做法还是我应该为每个页面制作单独的控制器?
会有一个会员区需要登录。为此创建一个区域是个好主意吗? 也许像:xxx.com/member/stuff/edit/1
然后我需要创建一个“常规”区域还是我可以将“关于”放在根目录中,如下所示:xxx.com/about/contact而不是 xxx.com/general/about/contact ?
母版页怎么样。登录时和未登录时该页面看起来非常相似。为此使用两个母版页并尝试使用部分代码重用代码(如页脚和菜单)是一种好的做法吗?
我只使用过一点点 MVC 2,对于像这样的全新项目,不使用 MVC 2 RC 是不是很愚蠢?
任何答案或建议都将受到高度赞赏。 谢谢
I'm setting up a new project and would like to have some tips about it so it will be done right from the start.
Simply put, this is my project:
There will be some about/info pages: about us, contact, how to.. Is it good practice to then create a AboutController or should i make seperate controllers for each page?
There will be a member area which needs login. Is it a good idea to create an Area for this?
Maybe like: xxx.com/member/stuff/edit/1Would I then need to create a "general" Area or could i just put "About" in the root, like this: xxx.com/about/contact instead of xxx.com/general/about/contact ?
What about master pages. The page will look very much alike when logged in, and when not. Is it good practice to have two master pages for this and try to reuse code (like the footer and menu) with partials?
I've only worked a little bit with MVC 2, is it stupid to not go with MVC 2 RC for a brand new project like this?
Any answers or advice is highly appreciated.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通常有一个主页或关于(或两者)控制器来容纳这些页面。通常不需要单独的控制器。在我的大多数网站中,这些几乎都是不接受 POST 的静态内容页面,因此控制器无论如何都非常薄。
这个决定是相当主观的。我建议,如果您不清楚何时以及为何需要一个区域,那么就不要使用它。另外,如果您的应用程序的唯一区域有我们登录的会员,但没有,那么似乎不需要区域。
在根中,即“一般”区域。
对于这种情况,我不会使用两个大师。我的大多数网站的所有变化都是一些标题内容(登录或注销链接的存在)。
我所做的是创建一个 Html Helper 来有条件地呈现一个或另一个控件:
MVC 2? MVC 3 怎么样? MVC 3 最近发布了。它包含 Razor 视图引擎,因此我认为它绝对值得使用。我认为没有理由不在新项目中使用 MVC3。
I usually have a Home or About (or both) Controller that houses these pages. Separate controllers are not usually necessary. In most of my sites these are almost all static content pages that do not accept POST, so the controllers are very thin anyway.
This decision is quite subjective. I would suggest that if you don't have a clear understanding when and why you want an area, then don't use one. Also, if the only area's your application has our logged-in members and not, then it seems like Areas are not needed.
In the root, that is the "general" area.
I do not use two masters for this situation. All that changes for most of my sites is some header content (presence of log in or log out link).
What I do instead is create an Html Helper to conditionally render one control or another:
MVC 2? How about MVC 3? MVC 3 was released recently. It includes the Razor view engine, and because of that I would say it is definitely worth using. I see no reason not to use MVC3 for a new project.