i need to make response from back end on web api on asp.net core 2.2
so that what shape of function that represent response or how to make function represent response ?
to clear more
public class Users
{
public string username { get; set; }
public string password { get; set; }
public string MessageStatus { get; set; }
public int StatusCode { get; set; }
public string StatusText { get; set; }
public string client_ip { get; set; }
public string BrowserInfo { get; set; }
public List<Branches> Branches { get; set; }
public string LoginTime { get; set; }
public string browserinfo { get; set; }
}
which is correct number 1 or 2 .
1- as following
[HttpPost(Contracts.ApiRoutes.Login.UserLogin)]
public IActionResult PostUserLogins([FromBody]Users user)
{
}
2- as following
public IActionResult PostUserLogins([FromBody]string username ,string password,string browserinfo,string client_ip,string )
{
}
or what correct please can you tell me what is correct ?
The first one is correct.When receiving the data, you can only have one [FromBody] parameter. So that doesn't work for receiving multiple parameters (unless you can put all but one into the URL like this: https://localhost:44372/Security/Login?username=aa&password=bb).
Best Regards,
Rena
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
You are using the ApiController attribute? By default complex types are taken from the body and simple types from the route or query string. If don't have any reason to change this, just stick with the default behavior.
It is recommended to use the first option which passing object with json between client and server.
Do you have any issue with first option?
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
39 Points
359 Posts
How to represent body on JSON format as parameters on action post function ?
Sep 02, 2019 12:37 AM|ahmedbarbary|LINK
problem
How to represent body on JSON format as parameters on action post function ?
i have json body as following :
this is request come as json from ui or front end
i need to make response from back end on web api on asp.net core 2.2
so that what shape of function that represent response or how to make function represent response ?
to clear more
or what correct please can you tell me what is correct ?
Contributor
2690 Points
874 Posts
Re: How to represent body on JSON format as parameters on action post function ?
Sep 02, 2019 09:03 AM|Rena Ni|LINK
Hi ahmedbarbary,
The first one is correct.When receiving the data, you can only have one [FromBody] parameter. So that doesn't work for receiving multiple parameters (unless you can put all but one into the URL like this: https://localhost:44372/Security/Login?username=aa&password=bb).
Best Regards,
Rena
All-Star
48500 Points
18071 Posts
Re: How to represent body on JSON format as parameters on action post function ?
Sep 03, 2019 11:19 AM|PatriceSc|LINK
Hi,
You are using the ApiController attribute? By default complex types are taken from the body and simple types from the route or query string. If don't have any reason to change this, just stick with the default behavior.
Contributor
3310 Points
1607 Posts
Re: How to represent body on JSON format as parameters on action post function ?
Sep 25, 2019 08:52 AM|Edward Z|LINK
It is recommended to use the first option which passing object with json between client and server.
Do you have any issue with first option?
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.