Giter Site home page Giter Site logo

Comments (8)

xuzhg avatar xuzhg commented on August 23, 2024

@rahul7720 what's your attribute, i can't find it from your sample code.

Actually, attribute routing in OData is using:

  1. ODataRoutePrefixAttribute
  2. ODataRouteAttribute

Do you use them in your project?

Here's an example: https://github.com/OData/AspNetCoreOData/blob/master/test/Microsoft.AspNetCore.OData.Tests/Routing/Conventions/AttributeRoutingConventionTests.cs#L177-L178

from aspnetcoreodata.

rahul7720 avatar rahul7720 commented on August 23, 2024

@xuzhg
I'm decorating the odata controller with ApiControllerAttribute in order to leverage the advantages of it like:

  1. automatic model state validation
  2. binding source parameter inference (To avoid attributes like [FromBody] on method parameters)

Since ApiControllerAttribute requires an endpoint routing, I have decorated the OData controller with 'RouteAttribute'

How can I achieve my requirement with the version 8.0.0?

from aspnetcoreodata.

xuzhg avatar xuzhg commented on August 23, 2024

for "binding source parameter inference (To avoid attributes like [FromBody] on method parameters)", you can add the model binding attribute on the [FromBody] parameter type, so you can avoid [FromBody].

For your scenario, can you add the route attributes all in your controller to see the result?

from aspnetcoreodata.

rahul7720 avatar rahul7720 commented on August 23, 2024

@xuzhg

  1. "you can add the model binding attribute on the [FromBody] parameter type, so you can avoid [FromBody]" - Can you please provide a short example?
  2. I don't wan to check ModelState.IsValid on POST, PUT methods, instead I want that to happen automatically. [ApiController] took care of the Model State validation automatically. What is the alternative in 8.0.0?

from aspnetcoreodata.

xuzhg avatar xuzhg commented on August 23, 2024
  1. https://github.com/OData/AspNetCoreOData/blob/master/src/Microsoft.AspNetCore.OData/Formatter/ODataActionParameters.cs#L14

  2. I mean you can use [ApiController] and [ODataRouteAttribute] together on the action or controller.

from aspnetcoreodata.

rahul7720 avatar rahul7720 commented on August 23, 2024

@xuzhg

Using [ApiController] and [ODataRouteAttribute] together on the action throws runtime exception when program starts:

app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

Action 'TestProject.Controllers.StudentsController.Get (TestProject)' does not have an attribute route. Action methods on controllers annotated with ApiControllerAttribute must be attribute routed.

from aspnetcoreodata.

sag3ll0 avatar sag3ll0 commented on August 23, 2024

I prepared a (test project](https://github.com/sag3ll0/OData8NetCore5Test) to demonstrate my problem, which is that if you do not use the ApiController attribute, the POST request does not correctly receive input parameters. Added a description of the problem in the project.
If not use ApiController attribute in controller i get null value.
null

If enable ApiController and disable odata its will ok.

from aspnetcoreodata.

xuzhg avatar xuzhg commented on August 23, 2024

@sag3ll0 Sorry for delay. The failing is related to the case sensitive.
I replied it to you at https://github.com/sag3ll0/OData8NetCore5Test/issues/1

Thanks for your question.
By the way, I changed the attribute routing strategy.
If you are interested in, you can refer to https://devblogs.microsoft.com/odata/attribute-routing-in-asp-net-core-odata-8-0-rc/
and leave any comments for me. Thanks.

from aspnetcoreodata.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.