This question is because in my MVC project with ASP.NET CORE 2.0, I can not add the [FromUri] attribute
to my drivers.
I tried using libraries like System.Web.Http
, but I did not recognize them. Then install these from Nuget Microsoft.AspNet.WebApi.Core
"and" System.AppDomain.NetCoreApp
, which resulted in being able to use System.Web.Http
but due to ambiguity problems I was not allowed to use it, but if I found that [FromUri]
existed.
The main question is whether in ASP.NET core 2.0 MVC or WebApi exists [FromUri]
?
if it exists, how to use it?
The [FromUri] attribute is prefixed to the parameter to specify that the value should be read from the URI of the request, and the [FromBody] attribute is used to specify that the value should be read from the body of the request.
[FromQuery] - Gets values from the query string. [FromRoute] - Gets values from route data.
So, to answer your question, the need of the [FromBody] and [FromUri] attributes in Web API is simply to override, if necessary, the default behaviour as described above. Note that you can use both attributes for a controller method, but only for different parameters, as demonstrated here.
I think you might be looking for [FromQuery]
: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding#customize-model-binding-behavior-with-attributes
[FromUri]
is used in Asp.Net WebApi 2, not asp.net core
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With