...
/Creating an Action Method for Posting a Question
Creating an Action Method for Posting a Question
Learn to implement a question posting action method.
We'll cover the following...
Implementing action method for posting a question
Let’s implement an action method for posting a question:
We’ll start with the skeleton method. Add the following after the
GetQuestion
method:
[HttpPost]public ActionResult<QuestionGetSingleResponse>PostQuestion(QuestionPostRequest questionPostRequest){// TODO - call the data repository to save the// question// TODO - return HTTP status code 201}
Note that we use an HttpPost
attribute to tell ASP.NET that this method handles HTTP POST
requests.
Note that the method parameter type for questionPostRequest
is a class rather than a primitive type. Earlier, in the “Extending the GetQuestions action method for searching” section, we introduced ourselves to model binding and explained how it maps data from an HTTP request to method parameters. Well, model binding can map data from the HTTP body as well as the query parameters. Model binding can also map ...