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 82 karma points
    Oct 07, 2019 @ 11:18
    Predrag Andrejević

    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:

    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 28 posts 150 karma points
    Oct 09, 2019 @ 08:23

    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 3262 posts 11066 karma points MVP 5x admin c-trib
    Sep 30, 2020 @ 09:22
    Dave Woestenborghs

    Hi Pedrag,

    Could you post the code of your api controller.


Please Sign in or register to post replies

Write your reply to: