ASP.NET MVC子目录 [英] ASP.NET MVC subdirectories

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

问题描述

我仍然是一种新的MVC的,所以我希望这是简单的。

I'm still kind of new to MVC, so I'm hoping this is simple.

我需要的类别和子类别,潜在的多层次深,我想适当地安排我的项目。现在,我使用的外装即用MVC项目在VS2008。

I need categories and subcategories, potentially multiple levels deep, and I'm trying to organize my project appropriately. Right now I'm using the out-of-the-box MVC project in VS2008.

例如,假设我要定位到:
http://mysite.com/Products/Electronics/Computers/Laptops

For example, suppose I want to navigate to: http://mysite.com/Products/Electronics/Computers/Laptops

我可以把一个LaptopsController在我Controllers目录,在我的观点不同的ASPX文件的Latops目录,并添加一行映射到相应的控制器这个特定的路线我的Global.asax类做到这一点。

I can accomplish this by putting a LaptopsController in my Controllers directory, a Latops directory with the various aspx files in my Views, and adding a line to my Global.asax class that maps this specific route to the appropriate controller.

但我希望有一种方法可以自动映射路径,而同时保持目录结构干净,并在项目组织,因为会有很多不同的类别和产品。理想情况下,应该是我的项目控制器和视图物理目录,对应于URL路径中的目录。但我似乎无法使这项工作。

But I'm hoping there's a way to automatically map the route, while at the same time keeping the directory structure clean and organized in the project, since there will be a lot of different categories and products. Ideally there should be physical directories in my project for controllers and views, corresponding to the "directories" in the URL path. But I can't seem to make that work.

我看这样做主要定制您的路由几篇文章,但我preFER不如果可能的话。这似乎是它会是内置的,所以也许我只是失去了一些东西。

I've looked at a few articles about doing major customization to your routing, but I'd prefer not to if possible. This seems like it would be something built-in, so maybe I'm just missing something.

如果你能在正确的方向指向我,这将是真棒。

If you could point me in the right direction, that would be awesome.

推荐答案

最有可能你并不需要一个 LaptopsController ,只是一个的ProductsController 。在这种情况下,电子/电脑/笔记本电脑只是告诉的ProductsController 来显示哪些产品类别(通过路由值)

Most likely you don't need a LaptopsController, just a ProductsController. In this case, Electronics/Computers/Laptops just tells the ProductsController which category of Products to show (via route values).

这篇关于ASP.NET MVC子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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