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

标签 c# asp.net-mvc t4mvc

这是我的原始代码:

@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/

相关文章:

c# - 如何通过循环组合路径

c# - 如何在jquery中独立于浏览器捕获精确的td值

asp.net-mvc - DropDownListFor 带有自定义构建列表

c# - ASP.NET Core 中的模型绑定(bind)以将下划线映射到首字母大写属性名称

asp.net-mvc - T4MVC:如何与 say Url.Action 一起使用?

asp.net-mvc-3 - 为什么 T4MVC 引入虚拟 Controller 操作?

c# - T4MVC 何时会支持带有显式 HtmlHelpers 的 Razor 来渲染局部?

c# - 如何以编程方式在 2 个单独的窗口上的 DependencyProperty 对象之间添加 WPF 绑定(bind)

c# - 使用 ToObject 方法反序列化 Json 会产生默认属性值

asp.net - 如何在 asp.net BundleConfig 中忽略特定包以进行优化