C
C#2y ago
DeaDo

MapPost: Parameters are null

This is my Post endpoint
app.MapPost("/register", (UserRepo userRepo, RegisterDto RegisterDto ) =>
{
...
}
app.MapPost("/register", (UserRepo userRepo, RegisterDto RegisterDto ) =>
{
...
}
When sending a Request with this Payload
{RegisterDto: {Name: "Herbert"}}
{RegisterDto: {Name: "Herbert"}}
the Endpoint is hit, but the Name-Property in RegisterDto is still null with [FromBody] and [AsParameters] i have the same issue
public class RegisterDto
{
public string Name { get; set; }
}
public class RegisterDto
{
public string Name { get; set; }
}
What does the JSON have to look like so that it works?
5 Replies
DeaDo
DeaDoOP2y ago
{name: "dsadsadsa"}
{name: "dsadsadsa"}
just the name works fine, but at the client i want to serialize the whole object and send it
Angius
Angius2y ago
It is the whole object It has a single property The name of it is "Name"
DeaDo
DeaDoOP2y ago
eventually serializing the whole thing with the dto-name is not a good idea?
Angius
Angius2y ago
More like a "why" idea
DeaDo
DeaDoOP2y ago
it felt more intuitive when i try to send a nested json, when the name of the top is included Well i'll just make it the way it is supposed to be. Thx.
Want results from more Discord servers?
Add your server