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ć 8 posts 79 karma points
    1 week ago
    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 22 posts 134 karma points
    6 days ago
    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;

Please Sign in or register to post replies

Write your reply to:

Draft