MVC 4.0을 사용 중이고 각 컨트롤러에 대한 경로를 추가하려고합니다.하나 이상의 컨트롤러를 라우팅하는 MVC
음, 내 첫 컨트롤러의 이름은 CustomersController입니다. 추가 내가 을 한 경로는 다음과 같습니다 나는 응용 프로그램을 실행하고 때
routes.MapRoute(
name: "Customer",
url: "{controller}/{action}/{IdCustomer}",
defaults: new { controller = "Customers", action = "Index", IdCustomer = UrlParameter.Optional }
);
, 내가 색인 페이지에서 다음 링크 (목록) 얻을 :
http://localhost:6838/Customers/Create/5
http://localhost:6838/Customers/Edit/5
http://localhost:6838/Customers/Details/5
http://localhost:6838/Customers/Delete/5
확인, 좋은! 그것은 내가 찾고있는 것이지만, 이제는 내 문제를 시작하십시오. 나는 ItemsController라는 또 다른 컨트롤러, 추가 (동일한 액션을을 - 생성/편집/세부/삭제) 나는이 같은 경로를 추가하려고 :
routes.MapRoute(
name: "Item",
url: "{controller}/{action}/{IdItem}",
defaults: new { controller = "Items", action = "Index", IdItem = UrlParameter.Optional }
);
을하지만 지금은 결과가 다르다 ... 내가 무엇입니까 다음 링크 : 왜
http://localhost:6838/Items/Create?IdItem=1
http://localhost:6838/Items/Edit?IdItem=1
http://localhost:6838/Items/Detail?IdItem=1
http://localhost:6838/Items/Delete?IdItem=1
는 왜 ..?이 작동하지 않습니다 '(이 새로운 하나 를 첫 번째 경로 만 일하고 아니에요 왜 그냥!
안부를 추가 단
경로가 너무 일반적입니다. 이 행동이'Customers' &'Items' (id 이름에 따라 다름)에 특정 할 때 왜 아직도'{controller}'를 사용하고 있습니까? 'Customers/{action}/{IdCustomer}'또는'Items/{action}/{IdItem}'을 사용해야합니다. URL 생성은 순차적 테스트임을 기억하십시오. 파서가 사용할 첫 번째로 일치하는 URL입니다 (이 경우 고객 URL이 사용됩니다). –
나는 처음으로 노선을 사용하고 있습니다. 전에는 사용한 적이 없었습니다. 당신이 의미하는 바를 이해하는 것은 나에게 복잡합니다. – Dan
이제 이해했습니다 ... 감사합니다. @BradChristie – Dan