Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

 

How to send data to a Web API in Asp.Net Core.

 

In Angular, the data is sent to the Web API with http.post..)

The first parameter is the URL of the WebAPI and the second parameter is the values as key:value pair, i.e. "key:"value" is written

 

return this.http

      .post(this.url_Api_Base + "/1" , { title: 'Angular POST Request Example' } )

 

 

Asp.Net Core Controller

In the Asp.Net Core Controller, the web request arrives as HttpPost with a single ID and passes the data in the second parameter.

It is important that the data arrives as a key-value pair, i.e. it must be sent in Angular with http.post(id,id,'key:value').

 

[HttpPost("{id}")] 

        public async  Task<IActionResult> PostTimeRecord(int id, object objBody)

        {

 

 

Name

Value

Type

this.Request.Path

{/api/TimeRecords/1}

Microsoft.AspNetCore.Http.PathString

RootElement

ValueKind = Object : "{"title":"Angular POST Request Example"}"

System.Text.Json.JsonElement

                               

 

Mobile

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de