4

これは私の元のコードでした:

@Url.Action("LoginYoutube", "Account", new { returnUrl = Request.QueryString["ReturnUrl"] }, "http")

生成されるもの: http://localhost:2543/Account/LoginYoutube

T4MVC では、次のことを行います。

Url.Action(MVC.Account.LoginYoutube().AddRouteValue("returnUrl", Request.QueryString["ReturnUrl"]))

/Account/LoginYoutube を生成します。

http://localhost:2543を取得するには、「http」を含む最後のパラメーターが必要です。問題は T4MVC にあり、Url.Action() の呼び出しに 1 つのパラメーターしか配置できません。

どうすればこれを機能させることができますか?

4

2 に答える 2

7

T4MVCには確かに何かが欠けていますが、簡単に追加できるはずです。以下をお試しください。T4MVC.ttで、次を変更します。

    public static string Action(this UrlHelper urlHelper, ActionResult result) {
        return urlHelper.RouteUrl(result.GetRouteValueDictionary());
    }

    public static string Action(this UrlHelper urlHelper, ActionResult result, string protocol = null, string hostName = null) {
        return urlHelper.RouteUrl(null, result.GetRouteValueDictionary(), protocol, hostName);
    }

これにより、次のように書くことができます。

 @Url.Action(MVC.Account.LoginYoutube().AddRouteValue("returnUrl", Request.QueryString["ReturnUrl"]), "http")

これがどのように機能するかを教えてください。公式テンプレートでこれを変更するかどうかを決定できます。

于 2011-06-05T03:53:56.447 に答える
4

@David Ebbo: 参考までに、昨夜、この変更 (2.6.55) で新しいビルドをプッシュしました。

それは実際に MVCContrib グリッドを壊します。または、少なくとも以前の T4MVC で動作するコードでは、コンパイル エラーが発生しました。

CS0854: 式ツリーには、オプションの引数を使用する呼び出しまたは呼び出しが含まれていない可能性があります

グリッドを生成するコード:

Html.Grid(Model.Customers)
          .Columns(c =>
            {
                c.For(x => Html.ActionLink(x.Name, MVC.Partner.Edit(x.ID), new { @class = "ILPartnerEdit" }))
                    .Named(LanguageResources.Name);
...

しかし、これを.TTに追加することで解決しました(<3オープンソース):

        public static <#=HtmlStringType #> ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, object htmlAttributes)
        {
            return ActionLink(htmlHelper, linkText, result, new RouteValueDictionary(htmlAttributes));
        }
于 2011-06-15T13:15:41.717 に答える