0

我RouteConfig文件设置默认路由URL和属性路由?如何

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> 
+0

使用更好的控制器示例更新问题。这有点令人困惑。仅仅显示行动是不够的。 – Nkosi

回答

0

例如,如果控制器是EmployeeController

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

你可以在动作上使用多条路线。