We saw on how to define
custom attribute routing for Asp.Net
Core WebAPI action methods and how to access the action methods using the
custom Route. In this post we shall move a step further and see on how to use
custom routes to pass parameters to the action methods.
Let us create one more action method to the Department controller which accepts an id parameter in the route.
Let us create one more action method to the Department controller which accepts an id parameter in the route.
[HttpGet("GetDepartmentById/{id:int}")]
public
ActionResult GetById( int id)
{
var _context = new UserRegistrationContext();
return _context.Department.Find(id);
We can invoke this action method as follows, notice that we are passing the parameter values in the route instead of passing them as query string parameters.
No comments:
Post a Comment