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”的参数才能获得http://localhost:2543。问题在于 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 网格。或者至少现在我得到了一个编译错误:

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 回答