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;
}
}
}
}
}
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.
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:
Link for reference. https://our.umbraco.com/Documentation/Reference/Events/EditorModel-Events/index-v7
I hope that helps
Paul
is working on a reply...