Copied to clipboard

Flag this post as spam?

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


  • Gibran Shah 69 posts 240 karma points
    Dec 29, 2019 @ 23:29
    Gibran Shah
    0

    How do I know my content Id?

    Hello,

    How can I know my content Id? I have a decimal field in my content page and I want to know the Id. How can I figure that out. Thanks.

  • Paul Seal 524 posts 2889 karma points MVP 7x c-trib
    Dec 30, 2019 @ 14:29
    Paul Seal
    0

    Hi Gibran

    Please can you clarify what you are struggling with here?

    You say you want to know what your content id is. In what context? Do you need to know it on the front end? If so that should be as simple as Model.Id or Model.Content.Id

    If you want to know it in Umbraco, you can see it at the end of the url.

    You have mentioned a decimal field, are you trying to populate that with the id of your content item? It is a bit pointless to do this as you already have the id as mentioned above. You could do it with the SendingContentModel event like this:

    using Umbraco.Core;
    using Umbraco.Core.Events;
    using Umbraco.Core.Models;
    using Umbraco.Web.Editors;
    using Umbraco.Web.Models.ContentEditing;
    
    namespace My.Namespace
    {
        public class MyEventHandler : ApplicationEventHandler
        {
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                EditorModelEventManager.SendingContentModel += EditorModelEventManager_SendingContentModel;
            }
    
            private void EditorModelEventManager_SendingContentModel(System.Web.Http.Filters.HttpActionExecutedContext sender, EditorModelEventArgs<Umbraco.Web.Models.ContentEditing.ContentItemDisplay> e)
            {
                if (e.Model.ContentTypeAlias == "myDocTypeAlias")
                {
                    var nodeId = e.Model.Properties.FirstOrDefault(f => f.Alias == "myPropertyAlias");
                    if (nodeId.Value == null || String.IsNullOrEmpty(nodeId.Value.ToString()))
                    {
                        nodeId = e.Model.Id;
                    }
                }
            }
        }
    }
    

    Link for reference. https://our.umbraco.com/Documentation/Reference/Events/EditorModel-Events/index-v7

    I hope that helps

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft