Controllers & Passing Value to Controller Via URL – Session 14

Controller & Passing Data to Controller via URL Feature Image

In this session of ASP.NET Core Tutorial, we continue our discussion about Controllers. Also we talk about passing value to Controller and Action method via URL and user request.

What is Controller in ASP.NET Core?

Generally Controller is a Class that implemented from Controller base Class. Its name has Controller suffix and each Controller has several Method that calls Action Method. Action Methods are responsible for processing requests.

In session 10, 11 and 12 we discussed about MVC structure and Routing which were related to this session. Thus if you have not review those sessions, we highly recommend reviewing mentioned sessions before starting this session.

Passing Data to Controllers Via Routing Pattern and Action Method Input Parameters

We can modify our Web App routing pattern to enable it to receive our required data via URL. Then we can have access to that data in the called Action Method through Input Parameters. For instance, you can modify your Web App routing pattern same as below figure to enable it to receive “id” and “name” as part of URL. Later, within called Action Method you can reach the Data via assigned Input Parameters.

Just bear in mind, Input Parameters of Action method should be exactly the same as naming in Routing Pattern.

Passing Data to Action Method via Query String and Input Parameters

Moreover, end-users can send their data to Action Method through Query String. Then, same as pervious way, you can have access to provided data in Action Method with Input Parameters.

Passing Value to Action Method via Query String and Request.Query

Last but not least, we can send data to our Action Request with Query String same as previous example. But this time we don’t need to mentioned our Query String name as Input Parameters. Rather, Action Method can have access to the passed data via Request.Query method.

If you need more details, watch this session video. Also, for being updated about our coming sessions, follow us on Instagram, Facebook, Telegram or YouTube and you can have access to list of all sessions HERE.

You can download this Session Slides form HERE

0.00 avg. rating (0% score) - 0 votes


0 0 votes
Article Rating

Inline Feedbacks
View all comments