From the course: Learning ASP.NET Core MVC

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Pass parameters to controller actions

Pass parameters to controller actions

From the course: Learning ASP.NET Core MVC

Start my 1-month free trial

Pass parameters to controller actions

- [Instructor] One great thing about controller actions is that they really are just methods, which means that if you want to pass data into them, you just go ahead and define a parameter on the method, and ASP.NET Core MVC will automatically populate that parameter from the request. For example, in the blog application I'm building, I'll need to be able to access a specific blog post by some kind of identifier. And I'll do that by passing the value of that identifier through a method parameter on the action. To demonstrate, I'll add another action to the blog's controller by simply defining a new method named Post. I'll have this new method accept a string parameter named id. And I'll have this method simply return the value of the parameter right back to the user as content. The name of this id parameter is very important as ASP.NET Core MVC uses this name to extract the value from somewhere in the request, such as a query string or the body of a form post. In this case, I used the…

Contents