Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T4MVC Doesn't work property with Url.Action()

This was my original code:

@Url.Action("LoginYoutube", "Account", new { returnUrl = Request.QueryString["ReturnUrl"] }, "http")

Which would generate: http://localhost:2543/Account/LoginYoutube

With T4MVC I do:

Url.Action(MVC.Account.LoginYoutube().AddRouteValue("returnUrl", Request.QueryString["ReturnUrl"]))

and that generates: /Account/LoginYoutube

I need the last parameter with "http" in order to get the http://localhost:2543. The problem is with T4MVC I can only put 1 parameter for the call to Url.Action().

How can I get this to work?

like image 855
Ryan Avatar asked Dec 22 '22 13:12

Ryan


1 Answers

T4MVC is indeed missing something here, but it should be easy to add. Please try the following. In T4MVC.tt, change:

    public static string Action(this UrlHelper urlHelper, ActionResult result) {
        return urlHelper.RouteUrl(result.GetRouteValueDictionary());
    }

to

    public static string Action(this UrlHelper urlHelper, ActionResult result, string protocol = null, string hostName = null) {
        return urlHelper.RouteUrl(null, result.GetRouteValueDictionary(), protocol, hostName);
    }

This should allow you to write:

 @Url.Action(MVC.Account.LoginYoutube().AddRouteValue("returnUrl", Request.QueryString["ReturnUrl"]), "http")

Please let me know how that works, so we can decide whether to change this in the official template.

like image 140
David Ebbo Avatar answered Jan 04 '23 23:01

David Ebbo