I am working on my first MVC project and using attribute routing in my controllers. I have a little problem with one of my actions that has two possible route paths. The routes themselves work, but the generated actionLinks are not to my liking.
Routes
[Route("add")] [Route("{parentId:int?}/add")]
ActionLink Definition:
@Html.ActionLink("Add Category", "Add", "Category", new { parentId = @Model.CurrentCategoryId}, new { @Class = "btn btn-primary"})
This works, but if currentCategoryId is not null, the link:
/categories/add?parentId=2
but what I would like to see (which rises when you manually roll the URL):
/categories/2/add
Anyway, can I achieve this with actionLink or any other MVC magic?
source share