Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Predrag Andrejević 10 posts 84 karma points
    Oct 07, 2019 @ 11:18
    Predrag Andrejević
    0

    A field initializer cannot reference the non-static field, method, or property 'UmbracoApiControllerBase.Services'

    I'm making an Web API that needs to have CRUD methods and I'm stuck at POST. One of the reasons is the title error that I get with this line of code:

    IContentService contentService = Services.ContentService;

    I've pasted that line from this link: https://our.umbraco.com/documentation/Reference/Management/Services/ConsentService/

    Basically, I need to make API POST method that'll, when called, create new child node (just like you can do in the Umbraco backoffice) from JSON that's passed in the request body and from what I've seen, I need ContentService in order to make that possible (if there's a better way to do that, please post it). Thanks in advance!

    EDIT: I've solved that error by putting contentService in the POST method body (I've declared it globally first).

  • Sibren 39 posts 211 karma points c-trib
    Oct 09, 2019 @ 08:23
    Sibren
    0

    Do you want the ConsentService or the ContentService? You are linking to the ConsentService.

    But you can use the following: IContentService contentService = ApplicationContext.Current.Services.ContentService;

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Sep 30, 2020 @ 09:22
    Dave Woestenborghs
    0

    Hi Pedrag,

    Could you post the code of your api controller.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft