创建无区域控制器的子文件夹 [英] Create sub folders in the controller without Areas

查看:206
本文介绍了创建无区域控制器的子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个MVC 3 Web应用,我想创造的东西是这样的:

I am developing a MVC 3 Web app and I want to create something like this:

/Controller
      /Blog
         BogController.cs
         ViewsController.cs
         ArticlesController.cs
      /Customers
         SalesController.cs
         ProductsController.cs          
      HomeController.cs
/Views
     /Blog
        Index.aspx
        Summary.aspx
        /Views
           Index.aspx
           Admin.aspx
           Show.aspx
       /Articles
          Show.aspx
          Admin.aspx
    /Customers
       /Sales
          Index.aspx
          Totals.aspx
       /Products
          Index.aspx
          Promotions.aspx
     /Home
       Index.aspx

<一个href="http://stackoverflow.com/questions/1748960/asp-net-mvc-create-sub-folders-in-the-controller">ASP.NET MVC。在控制器创建子文件夹

不过,他们回答这个家伙的MVC 2和MVC 3财产MapAreas解决方案不退出(或至少它不会出现在我身上)

But in the solution that they answer to this guy was for MVC 2 and in MVC 3 the property MapAreas doesn't exits (or at least it doesn't appear to me)

所以,我能做些什么来样订做/管理/用户/ EditUser?ID = 2的例子吗?一个结构

So what i can do to build an structure like /Admin/Users/EditUser?id=2 for example?

如果我需要创建一个路由规则,你能不能给我写的如何做到这一点的例子。

If i need to create a route rule, can you write me an example of how to do it.

推荐答案

路由规则是肯定要走的路。为了使结构像你提到的,这样写的路由规则:

Routing rules are definitely the way to go. To make a structure like you mentioned, write the route rule like this:

routes.MapRoute(
    "user_routing",
    "Admin/{controller}/{action}?id={id}",
    new { }
);

然后创建一个名为UsersController中的控制器,并用ID作为参数的操作:

Then create a controller named UsersController, and an action with id as a parameter:

public ActionResult EditUser(string id) {
    ...
}

这篇关于创建无区域控制器的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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