2016-07-19 2 views
0

사용자가 프로젝트 정보를 추가 할 수있는 시스템을 만듭니다. 시스템의 일부에는 프로젝트에서 중단되는 하위 양식이 있습니다. 임은 라우팅 설정 방법에 대해 머리를 쓰려고 노력 중이며 아래와 같은 경로를 만들 수 있는지 궁금해했습니다.mvc 프로젝트에 사용자 지정 경로 추가

/project/ 
/project/12345 
/project/12345/bid - id is the same as the project e.g 12345 
/project/12345/bid/create - id is the same as the project e.g 12345 
/project/12345/bid/edit - id is the same as the project e.g 12345 

이 좋은 생각인가 아니면

/bid 
/bid/create - id is the same as the project e.g 12345 
/bid/12345 - id is the same as the project e.g 12345 
/bid/12345/edit - id is the same as the project e.g 12345 

답변

0

아니 큰 차이가해야 할 더 좋을 것이다. 하지만 첫 번째 버전을 사용하는 것이 좋습니다. /project 이외의 다른 메시지가 나타날 수 있습니다. 또한 이러한 URL은보다 분명하고 자기 설명 적입니다.

구현하려면 attribute routing을 살펴보십시오. 그것은 당신의 요구를 완벽하게 충족시킬 것입니다.

:

[RoutePrefix("project")] 
public class ProjectController : Controller 
{ 
    // eg: /project 
    [Route("")] 
    public ActionResult Index() { ... } 

    // eg: /project/1234 
    [Route("{projectID:int}")] 
    public ActionResult Project(int projectID) { ... } 

    // eg: /project/1234/bid 
    [Route("{projectID:int}/bid")] 
    public ActionResult Bid(int projectID) { ... } 

    // eg: /project/1234/bid/create 
    [Route("{projectID:int}/bid/create")] 
    Public ActionResult CreateBid(int projectID) { ... } 

    // so on 
} 

그리고 등록하는 것을 잊지 마세요 같은 경로 :

가 공개 웹 사이트 나는이 작은 설명을 추가합니다 않는 한 나는 다음과 같이 뭔가를 갈 것
public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

    // other routes if you need 

    routes.MapMvcAttributeRoutes(); 
} 
0

SEO 용 URL.

/입찰/789

/입찰/생성

/입찰/편집/12345

routes.MapRoute(
     name: "Default", 
     url: "{controller}/{id}/{action}", 
     defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
    ); 
관련 문제