Copied to clipboard

Flag this post as spam?

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


  • JoskerVemeulen 68 posts 262 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 548 posts 1840 karma points MVP 3x 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 5045 posts 15476 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 68 posts 262 karma points
    Mar 22, 2019 @ 11:45
    JoskerVemeulen
    0

    I ended up using CreateAndSave Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft