Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Similar thing also came up on the T4MVC Forum (<a href="http://forums.asp.net/t/1503043.aspx" rel="nofollow noreferrer">this thread</a>). I think I'll go ahead and add support for it in T4MVC.</p> <p>Actually, I just thought of an interesting way to solve this. The problem with adding an overload to pass extra arguments is that you'd need to add similar overloads to all the other T4MVC extension methods that take an ActionResult, which can get messy.</p> <p>Instead, we can use a fluent approach to make this available everywhere with little effort. The idea is that you'll write:</p> <pre><code>&lt;%= Html.ActionLink( bar.Name, MVC.Bar.Details(bar.ID) .AddRouteValues(new {fooKey = bar.Foo.Key, barKey = bar.Key}))%&gt; </code></pre> <p>Or if you only needed to add one value:</p> <pre><code>&lt;%= Html.ActionLink( bar.Name, MVC.Bar.Details(bar.ID) .AddRouteValue("fooKey", bar.Foo.Key))%&gt; </code></pre> <p>Here is how AddRouteValues is implemented:</p> <pre><code>public static ActionResult AddRouteValues(this ActionResult result, object routeValues) { return result.AddRouteValues(new RouteValueDictionary(routeValues)); } public static ActionResult AddRouteValues(this ActionResult result, RouteValueDictionary routeValues) { RouteValueDictionary currentRouteValues = result.GetRouteValueDictionary(); // Add all the extra values foreach (var pair in routeValues) { currentRouteValues.Add(pair.Key, pair.Value); } return result; } public static ActionResult AddRouteValue(this ActionResult result, string name, object value) { RouteValueDictionary routeValues = result.GetRouteValueDictionary(); routeValues.Add(name, value); return result; } </code></pre> <p>It would be great if you could give this a try and let me know how that works for you.</p> <p>thanks, David</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload