내 프로젝트에서 영역 내부의보기에 URL을 만들려고합니다.영역을 사용할 때 T4MVC가 ActionLink에 대한 잘못된 URL을 만듭니다.
<a class="btn" href="/MyArea/MyController/MyCurrentAction?Count=3&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D">Cancel</a>
내가 T4MVC의 코드를 찾고이 것을 발견 갔다 :
@Html.ActionLink("Cancel", MVC.MyArea.MyController.Index(), new { @class = "btn" })
내가 브라우저에서 결과를 확인, 생성 된 코드는 다음과 같다 :
코드는 이것이다 합니다 (T4Extensions
클래스 내에) 위의 코드를 생성하는 방법은 명백하게
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, object htmlAttributes, string protocol = null, string hostName = null, string fragment = null) {
return htmlHelper.RouteLink(linkText, null, protocol, hostName, fragment, result.GetRouteValueDictionary(), htmlAttributes);
}
의 RouteLink
있어서의 b되지 result.GetRouteValueDictionary()
을 사용해야합니다.
따라서 ASP.NET MVC source code을 확인한 후 동일한 기능을 복제하려고 시도했습니다. 나는이 내 T4MVC을 변경했습니다 :
지금은 적어도 내가 만든 한 테스트를 위해, (물론, 좋은입니다) 작업,하지만 내가 뭔가 잘못하고 드릴 수public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, object htmlAttributes, string protocol = null, string hostName = null, string fragment = null) {
var t4mvcResult = result.GetT4MVCResult();
var actionName = t4mvcResult.Action;
var controllerName = t4mvcResult.Controller;
var routeValues = new RouteValueDictionary(t4mvcResult.RouteValueDictionary);
var htmlAttribs = new RouteValueDictionary(htmlAttributes);
return new MvcHtmlString(HtmlHelper.GenerateLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, linkText, null /* routeName */, actionName, controllerName, protocol, hostName, fragment, routeValues, htmlAttribs));
}
이 길은 저를 앞서 몇 가지 문제로 인도 할 수 있다고 생각합니다.
당신이 지적한대로이 방법을 변경했고 수정되었습니다! 그건 그렇고, T4MVC로 훌륭하게 해냈습니다. 감사! –
감사합니다. 이제 수정 사항이 새로운 2.7.0 빌드 (NuGet)에 있으므로 업데이트 할 수 있어야합니다. –