T4MVC不;无法使用Url.Action()的属性

本文关键字:Action 属性 Url T4MVC | 更新日期: 2023-09-27 17:58:28

这是我最初的代码:

@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个参数

我怎样才能让它发挥作用?

T4MVC不;无法使用Url.Action()的属性

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")

请让我知道它是如何工作的,这样我们就可以决定是否在官方模板中更改它。

@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));
        }