dave317
dave317

Reputation: 774

Combine asp-route-id with asp-route-all-data

Is there any way to make this work?

<a class="btn btn-info" asp-action="ActionName" asp-route-id="@item.ID"
                       asp-all-route-data="parms" >Action</a>

This generates the following link:

sitename.com/controller/action?parm1=parm1&parm2=parm2

etc. I want it to generate this:

sitename.com/controller/action/{id}?parm1=parm1&parm2=parm2

It seems as though you cannot combine the route-id with asp-route-all-data. It is a link on a table and so my ID changes with each row, the rest of the filters (searchstrings, pages, sorts, etc) do not change. Would save a lot of copying and pasting if this would work.

While writing this I realized I could probably make a Viewmodel with a Dictionary of items AND an IEnumerable of my Model, rather than just using my model as is. Is there any other (simpler) way of making this work?

Upvotes: 6

Views: 5535

Answers (1)

GRFRM
GRFRM

Reputation: 246

Putting the "asp-all-route-data" attribute before "asp-route-id" solves the problem.

<a class="btn btn-info" asp-action="ActionName" 
        asp-all-route-data="parms"             
        asp-route-id="@item.ID">Action</a>

And generates the following link:

sitename.com/controller/action/{id}?parm1=parm1&parm2=parm2

Upvotes: 5

Related Questions