stibay stibay - 3 months ago 96
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

Dave Paquette did a nice write up about many of the TagHelpers. Here's the one for the anchor tag helper: http://www.davepaquette.com/archive/2015/06/01/mvc-6-anchor-tag-helper.aspx

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

Comments