Asp.net MVC相同视图名称,不同的路径 [英] Asp.net MVC same view name, different paths

查看:133
本文介绍了Asp.net MVC相同视图名称,不同的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有包含名称相同的看法多路径文件夹结构:

I want to have multiple path folder structure that contain same name views:

/profile.aspx
/admin/profile.aspx
/user/editpost.aspx
/admin/editpost.aspx

/Controllers
  |- PostController.cs
  |- ProfileController.cs

我希望能够有一个文件夹中所有的常规网页,并在另一个文件夹管理页面。我需要整理我的视图文件夹,如:

I want to be able to have all the regular pages in a folder and the admin pages in another folder. Do I need to organize my Views folder like:

/Views
  /User
    /Story
      |- editpost.aspx
    /Profile
      |- profile.aspx
  /Admin
    /Story
      |_ editpost.aspx
    /Web
      |- profile.aspx

还是有办法,我可以做到这一点:

or is there a way I can do this:

/User
  /Views
    /Story
      |- editpost.aspx
    /Profile
      |- profile.aspx
/Admin
  /Views
    /Story
      |_ editpost.aspx
    /Web
      |- profile.aspx

另外,我怎么code /组织/使用单独的控制器用于/用户和/管理员潜在地具有相同的名称?

Also, how do I code/organize/use separate controllers for /User and /Admin that potentially have the same name?

让我知道如果我一直不清楚。

Let me know if I have been unclear.

谢谢!

推荐答案

一个与第一个版本的主要问题(和所有课程的RC和Beta的)是ASP.NET MVC不支持的领域。领域是什么,对于ASP.NET MVC的替代框架已经支持了一段时间,当你的项目获取到一个合理的规模,你打算在同一个文件夹中可能数百个控制器(各自有独立的名字),你的$落得C $ c为将是很难通过排序。

One of the major problems with the first release (And all the RC and Beta's of course) is that ASP.NET MVC does not support areas. Areas are something that alternative MVC frameworks for ASP.NET have supported for some time and when your project gets to a reasonable size you're going to end up with possibly hundreds of controllers (all with unique names) in the same folder and your code is going to be very hard to sort through.

您的想法是非常合情合理的,我希望ASP.NET MVC框架的未来实例支持领域的开箱(这么说)。在平均时间可以很容易地创建ASP.NET MVC的顶部自己领域的框架。

Your idea makes perfect sense and I hope that future instances of the ASP.NET MVC framework supports areas out of the box (so to speak). In the mean time it's easy to create your own Areas framework on top of ASP.NET MVC.

下面是一些帖子,这将帮助你:

Here are some posts that will help you out:

  • Phil Haack's Post Posted already by çağdaş
  • Steve Sanderson's Response A response by Steve to Phil's post taking it futher
  • My Post on Localisation using Areas
  • Another one of my posts on areas with strongly typed view names

希望他们是对您有所帮助。

Hopefully they're helpful to you.

这篇关于Asp.net MVC相同视图名称,不同的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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