How can I get the contentid of the block from within it's view?
The ID is in the ContentReference of the block, if you're using a controller and a view/viewmodel you want to cast the Block in the controller method to IContent e.g.
public override ActionResult Index(CachedBlock currentBlock)
var content = (IContent) currentBlock;
var id = content.ContentLink.ID;
// Set in viewmodel object
If you're using a controllerless block you can do the same in the View in some inline C# or a C# block at the top of the page.
Would you have a suggestion for an inline C# approach? My block does not have a controller.
Yes as I said in my reply on the last line it's the same code just put it in a C# code block at the top of the view and cast the model.
Oh sorry, I misunderstood. Re-reading your commend you do indeed suggest that alternative. Thank you I am going to try that.