나는 비슷한 경로를 가진 asp.net MVC 응용 프로그램이 있습니다Asp.Net MVC : 정수 값을 올바르게 렌더링하도록 Html.ActionLink를 얻으려면 어떻게해야합니까?
routes.MapRoute("Blog",
"{controller}/{action}/{year}/{month}/{day}/{friendlyName}",
new { controller = "Blog", action = "Index", id = "", friendlyName="" },
new { controller = @"[^\.]*",
year = @"\d{4}",
month = @"\d{2}",
day = @"\d{2}" }
);
내 컨트롤러 액션 메소드 서명은 다음과 같습니다 내보기에서
public ActionResult Detail(int year, int month, int day, string friendlyName)
{ // Implementation... }
는, 내가 좋아하는 뭔가를하고 있어요 :
<%= Html.ActionLink<BlogController>(item => item.Detail(blog.PostedOn.Year, blog.PostedOn.Month, blog.PostedOn.Day, blog.Slug), blog.Title) %>
ActionLink에서 생성 된 URL이 작동하는 동안 URL 재 작성보다는 쿼리 문자열 변수가 사용됩니다.
예를 들어, 그것은 생산하는 것/블로그/세부/내-슬러그? 년 = 2008 & 월 = 7 & 일 = 5 대신에/블로그/세부/2008/07/05/내-슬러그
예상 URL이 나오도록 정수 값을 적절하게 채우기 위해 ActionLink의 제네릭 버전을 얻는 방법이 있습니까?
감사
짐
최적의 해결책은 아니지만, 나는 이것이 작동 할 것이라는 것을 알고 있습니다. –