Breaking

Monday, July 12, 2021

ASP.NET Core–Generate URL using Url.Action

I needed to generate a URL that I could return inside an ASP.NET Controller.

Thanks to the built-in UrlHelper that is something that even I can do. At least that was what I thought…

This is the code I tried:

Surprisingly this didn’t work.  It turns out that the controller argument needs the controllername without the controller suffix.  So in my example above ProductController should be Product instead.

I changed it to this:

Still refactor friendly but unfortunately a lot less readible.

No comments:

Post a Comment