T4MVC Property does not work with Url.Action ()

This was my original code:

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

To generate: http: // localhost: 2543 / Account / LoginYoutube

With T4MVC I do:

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

and which generates: / Account / LoginYoutube

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

How can I make this work?

+4
source share
2 answers

T4MVC is really something here, but it needs to be easily added. 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 will allow you to write:

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

Please let me know how this works, so we can decide if this should be changed in the official template.

+7
source

@David Ebbo: FYI I made a new collection last night with this change (2.6.55).

This actually destroys the MVCContrib grid. Or at least with the code that worked with the previous T4MVC, now I got a compilation error:

CS0854: The expression tree may not contain a call or a call that uses optional arguments

Code for generating the grid:

 Html.Grid(Model.Customers) .Columns(c => { c.For(x => Html.ActionLink(x.Name, MVC.Partner.Edit(x.ID), new { @class = "ILPartnerEdit" })) .Named(LanguageResources.Name); ... 

But decided by adding this to .TT (<3 open source):

  public static <#=HtmlStringType #> ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, object htmlAttributes) { return ActionLink(htmlHelper, linkText, result, new RouteValueDictionary(htmlAttributes)); } 
+4
source

All Articles