ASP.NET MVC中的路由区域

问题描述

我有一个用户区,我想从用户区URL中删除控制器

我尝试使用

[Route("User/ChangePassword")
public ActionResult ChangePassword()

但是它不起作用!

RouteConfig

  public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapMvcAttributeRoutes();
            routes.MapRoute(
                name: "Default",url: "{controller}/{action}/{id}",defaults: new { controller = "Home",action = "Index",id = UrlParameter.Optional }
            );
        }

UserAreaRegistration

 public override string AreaName 
        {
            get 
            {
                return "User";
            }
        }

        public override void Registerarea(AreaRegistrationContext context) 
        {
            context.MapRoute(
                "User_default","User/{controller}/{action}/{id}",new { action = "Index",id = UrlParameter.Optional }
            );
        }

那么我如何为用户区域生成该URL?

domain.com/user/changepassword

解决方法

您可以在Route.config中添加名称空间。它将指向该区域的配置路径

BluetoothAdapter myBTAdapter = BluetoothAdapter.getDefaultAdapter();
myBTAdapter.setName("new_name");