Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FromUri in ASP.NET CORE 2.0

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?

like image 996
Alexis Zapata Avatar asked Jan 10 '18 19:01

Alexis Zapata


People also ask

What is FromUri?

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.

What is the difference between FromRoute and FromQuery?

[FromQuery] - Gets values from the query string. [FromRoute] - Gets values from route data.

Why are the FromBody and FromUri attributes needed in asp net Web API?

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.


1 Answers

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

like image 77
Mike_G Avatar answered Sep 28 '22 05:09

Mike_G