.NET MVC 项目的结构

发布于 2024-10-13 12:21:40 字数 545 浏览 4 评论 0原文

我正在建立一个新项目,并希望获得一些有关它的提示,以便从一开始就可以完成它。

简而言之,这是我的项目:

  1. 将会有一些关于/信息页面:关于我们、联系方式、如何...然后创建一个 AboutController 是一个好的做法还是我应该为每个页面制作单独的控制器?

  2. 会有一个会员区需要登录。为此创建一个区域是个好主意吗? 也许像:xxx.com/member/stuff/edit/1

  3. 然后我需要创建一个“常规”区域还是我可以将“关于”放在根目录中,如下所示:xxx.com/about/contact而不是 xxx.com/general/about/contact ?

  4. 母版页怎么样。登录时和未登录时该页面看起来非常相似。为此使用两个母版页并尝试使用部分代码重用代码(如页脚和菜单)是一种好的做法吗?

  5. 我只使用过一点点 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:

  1. 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?

  2. 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/1

  3. Would 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 ?

  4. 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?

  5. 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 技术交流群。

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

发布评论

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

评论(1

随波逐流 2024-10-20 12:21:40

将会有一些关于/信息页面:
关于我们、联系方式、如何...好不好
练习然后创建一个
关于控制器还是我应该做
每个页面都有单独的控制器?

我通常有一个主页或关于(或两者)控制器来容纳这些页面。通常不需要单独的控制器。在我的大多数网站中,这些几乎都是不接受 POST 的静态内容页面,因此控制器无论如何都非常薄。

将会有一个会员区
需要登录。这是一个好主意吗
为此创建一个区域?

这个决定是相当主观的。我建议,如果您不清楚何时以及为何需要一个区域,那么就不要使用它。另外,如果您的应用程序的唯一区域有我们登录的会员,但没有,那么似乎不需要区域。

然后我需要创建一个
“一般”区域或者我可以直接输入
根目录中的“关于”

在根中,即“一般”区域。

母版页怎么样。该页面将
登录后看起来非常相似
以及何时不。这是一个好的做法吗
为此有两个母版页并尝试
重用代码(例如页脚和
菜单)带有部分内容?

对于这种情况,我不会使用两个大师。我的大多数网站的所有变化都是一些标题内容(登录或注销链接的存在)。

我所做的是创建一个 Html Helper 来有条件地呈现一个或另一个控件:

public static class PackageThumbnailHelper
{
    public static MvcHtmlString AuthenticationControls(this HtmlHelper helper)
    {
                if (helper.ViewContext.HttpContext.Request.IsAuthenticated) {
                    return helper.Partial(MVC.Shared.Views.LoggedOnAuthenticationControls);
                } else {
                    return helper.Partial(MVC.Shared.Views.NotLoggedOnAuthenticationControls);
                }
    }
}

我只接触过一点 MVC
2、不走MVC 2是不是很蠢
像这样的全新项目需要 RC 吗?

MVC 2? MVC 3 怎么样? MVC 3 最近发布了。它包含 Razor 视图引擎,因此我认为它绝对值得使用。我认为没有理由不在新项目中使用 MVC3。

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?

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.

There will be a member area which
needs login. Is it a good idea to
create an Area for this?

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.

Would I then need to create a
"general" Area or could i just put
"About" in the root

In the root, that is the "general" area.

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 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:

public static class PackageThumbnailHelper
{
    public static MvcHtmlString AuthenticationControls(this HtmlHelper helper)
    {
                if (helper.ViewContext.HttpContext.Request.IsAuthenticated) {
                    return helper.Partial(MVC.Shared.Views.LoggedOnAuthenticationControls);
                } else {
                    return helper.Partial(MVC.Shared.Views.NotLoggedOnAuthenticationControls);
                }
    }
}

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?

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.

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