Copied to clipboard

Flag this post as spam?

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


  • JoskerVemeulen 67 posts 261 karma points
    Mar 22, 2019 @ 10:19
    JoskerVemeulen
    0

    CurrentPage Id in V8

    I have a contact controller to send a form and to save the content in a ContentList so the client can check the form submits.

                    var message = Services.ContentService.CreateContent(String.Format("{0} {1}", model.ContactFirstname, model.ContactLastname), CurrentPage.Id, "contactForm");
    

    This use to work in V7, but v8 gives an error on the CurrentPage.id => cannot convert 'int' to Umbraco.Core.Udi'

    Any ideas?

  • Frans de Jong 522 posts 1762 karma points c-trib
    Mar 22, 2019 @ 10:35
    Frans de Jong
    2

    You need a Udi instead of a id.

    You can get the Udi like this:

    GuidUdi currentPageUdi = new GuidUdi(CurrentPage.ContentType.ItemType.ToString(), CurrentPage.Key);
    

    Than use:

    var message = Services.ContentService.CreateContent(String.Format("{0} {1}", model.ContactFirstname, model.ContactLastname), currentPageUdi, "contactForm");
    
  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Mar 22, 2019 @ 11:44
    Sebastiaan Janssen
    0

    Or just use Create instead of CreateContent :)

    enter image description here

  • JoskerVemeulen 67 posts 261 karma points
    Mar 22, 2019 @ 11:45
    JoskerVemeulen
    0

    I ended up using CreateAndSave Thanks!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies