gpt4 book ai didi

c# - T4MVC 不适用于 Url.Action()

转载 作者:太空狗 更新时间:2023-10-30 00:16:36 25 4
gpt4 key购买 nike

这是我的原始代码:

@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 确实在这里缺少一些东西,但应该很容易添加。请尝试以下操作。在 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")

请告诉我它是如何工作的,以便我们决定是否在官方模板中更改它。

关于c# - T4MVC 不适用于 Url.Action(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6240568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com