【问题标题】:set Default routing url and attribute route ? how to设置默认路由 url 和属性路由?如何
【发布时间】:2018-01-14 00:11:56
【问题描述】:

我的 RouteConfig 文件是

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapMvcAttributeRoutes();
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Employee", action = "Index", id = UrlParameter.Optional }
        );

我的控制器是

 [Route("EMS/{Employee}")]
    public ActionResult Index()
    {
        return View();
    }

我的工作网址是 http://localhost:6628/EMS/Employee

但我想使用简单的http://localhost:6628 作为我的默认网址,因为没有 MapMvcAttributeRoutes() 它工作正常

我如何在同一个项目中同时使用它们,例如默认控制器操作必须是员工和索引,并且点击路由 url EMS/员工像这样工作

  <td>
    <input type="button" id="ROUTE" value="ROUTE"   onclick="location.href='@Url.Action("Employee", "EMS")'" class="btn-info" />
                        </td>

【问题讨论】:

    标签: asp.net asp.net-mvc routing asp.net-mvc-routing asp.net-mvc-5


    【解决方案1】:

    如果控制器例如是EmployeeController

    public class EmployeeController {    
        [HttpGet]
        [Route("")] //Matches GET /
        [Route("EMS/Employee")] //Matches GET EMS/EMployee
        public ActionResult Index() {
            return View();
        }
    }
    

    您可以在操作上使用多个路由。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-03
      • 1970-01-01
      • 2016-10-02
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      相关资源
      最近更新 更多