Pass parameters to action method in ASP.NET Core

One of the simplest and easiest ways to pass parameters to an action method is passing it via the URL. The following code snippet illustrates how you can pass parameters in the URL.

[HttpGet]
[Route("Default/GetAuthor/{authorId:int}")]
public IActionResult GetAuthor(int authorId)
{
   var data = authorRepository.GetAuthor(authorId);
   return View(data);
}

The URL to the endpoint is:

GET: http://localhost:8061/Default/GetAuthor/1

Here are some of links;

https://www.infoworld.com/article/3568209/how-to-pass-parameters-to-action-methods-in-asp-net-core-mvc.html

FavoriteLoadingAdd to favorites
Spread the love

Author: Shahzad Khan

Software developer / Architect