2012-03-09 7 views
1

私のプロジェクトでは、エリア内のビューにURLを作成しようとしています。
コードはこれです:私は、ブラウザで結果を表示すると、生成されたコードは以下の通りですT4MVCは、エリアを使用するときにActionLinkのURLを正しく作成しません。

@Html.ActionLink("Cancel", MVC.MyArea.MyController.Index(), new { @class = "btn" }) 

<a class="btn" href="/MyArea/MyController/MyCurrentAction?Count=3&amp;Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&amp;Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D">Cancel</a> 

私はT4MVCのコードを探して行って、これがあることがわかりました(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をチェックし、同じ機能を複製しようとしました。少なくとも私が行ったテストで、

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を変更しましたこの道が先に私にいくつかの問題につながる可能性があるということです。

答えて

1

ダーン、これは2.6.69の回帰のようです。実際にそれが以前に働いたことを確認するために2.6.68を試すことができますか?私は今2.6.69を非表示にしているので、他の人が新しいプロジェクトで自動的に(そして更新時に)それを取得しないようにしています。 http://mvccontrib.codeplex.com/workitem/7191また

は、あなたがそのバグで最後のコメントで述べた正確な修正を試みることができる:

これは悪い修正をトリガーバグでしたか?メソッドを次のように変更します。

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(), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 
    } 

ごめんなさい!

+0

私があなたが指摘したとおりにメソッドを変更し、修正されました!ちなみに、あなたはT4MVCで素晴らしい仕事をしています。ありがとう! –

+2

ありがとう!さて、修正は、2.7.2の新しいビルド(NuGet上)になったので、更新できるはずです。 –

関連する問題