stibay stibay - 1 year ago 454
ASP.NET (C#) Question

Asp action route data

In the old version of MVC 5 I could do this to pass route parameters

@Html.ActionLink("New item", "Suggestion", new ProductSuggestion() { Username = Model.Username }, new { @class = "btn btn-default" })

I am trying to get this to work with the new asp-action method and I figgured out I could do this as a workaround. But what is the correct syntax for this?

var a = new Dictionary<string, string> { { "Username", Model.Username } };

<a asp-action="Suggestion" asp-all-route-data="a" class="btn btn-default">New item</a>

Answer Source

Dave Paquette did a nice write up about many of the TagHelpers. Here's the one for the anchor tag helper:

Essentially you can do <a asp-route-myvar="myValue">

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download