Copied to clipboard

Flag this post as spam?

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


  • Casper Andersen 126 posts 508 karma points
    Jul 29, 2015 @ 10:55
    Casper Andersen
    0

    Umbraco.Core.Models.IContent Does not contain a definition for SetValue

    In my controller i am trying to update a node like this

    var cs = new ContentService();
    var opdatereHold = cs.GetById(CurrentPage.Id);
    

    this works fine.

    but when i get to

    opdatereHold.SetValue("holdNavn", clubTitle);
    

    then i get the error

    Umbraco.Core.Models.IContent Does not contain a definition for SetValue

    Anyone know what the problem might be ?

    I did some debugs and i can see that all information that is passed into the controller is correct

  • Casper Andersen 126 posts 508 karma points
    Jul 30, 2015 @ 06:48
    Casper Andersen
    102

    Figured it out, for some reason, SetValue cannot be used so instead i found i could use opdatereHold.Properties["holdNavn"].Value = clubTitle;

  • Chien - Thang Pham 1 post 21 karma points
    Dec 13, 2015 @ 04:57
    Chien - Thang Pham
    0

    Could you figure out the problem with SetValue? I'm facing with the same issue.

    The traditional method: opdatereHold.Properties["holdNavn"].Value = clubTitle; worked like a charm, but should we use this one instead of SetValue?

  • Dan Sørensen 102 posts 327 karma points
    Feb 01, 2016 @ 16:33
    Dan Sørensen
    0

    Im on the same road now :D

    But did anyone find out what to use ?

  • Bjarne Fyrstenborg 1280 posts 3990 karma points MVP 7x c-trib
    Mar 29, 2016 @ 09:39
    Bjarne Fyrstenborg
    0

    I have the same issue inside UmbracoApiController. Furthermore I noticed there isn't any SaveAndPublish method like when using ContentService inside a razor file inherited from Umbraco.Web.Mvc.UmbracoTemplatePage, but it has a SaveAndPublishWithStatus method.

    var newReview = contentService.CreateContent(reviewName, siteReviewArchive.Id, "Review", 0);
    newReview.SetValue("reviewName", review.First.name.ToString());
    
    contentService.SaveAndPublishWithStatus(newReview, 0, true);
    

    In razor template it used ContentService from ApplicationContext.Current.Services.ContentService, in WebApi controller just from Services.ContentService

    I can access the SetValue method via IntelliSense, but it seems to fail it this case. It works if I use the following instead:

    newReview.Properties["reviewName"].Value = review.First.name.ToString();
    

    /Bjarne

  • Jamie Attwood 201 posts 493 karma points c-trib
    Jul 12, 2023 @ 14:45
    Jamie Attwood
    0

    From another post that I just stumbled on.... I know it's a super old question, but anyone still on 7 that runs into this issue as I just did on an old instance - just explicitly cast your values to string instead of using var. The error message is misleading...I think when dynamic runs into ints (for example) it is not casting them correctly to the destination property type. Simply casting to string to match your property's expected type will allow you to continue to use .SetValue().

    Cheers,'

    Jamie

Please Sign in or register to post replies

Write your reply to:

Draft