Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 667
dave317 Avatar asked Oct 16 '22 21:10

dave317


1 Answers

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
like image 181
GRFRM Avatar answered Oct 21 '22 08:10

GRFRM