这是我的原始代码:
@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/