Try our conversational search powered by Generative AI!

Page level validation for a block property value in CMS edit view.


In CMS edit, Suppose if a page is having multiple blocks of the same type, a specific block property value should be unique across all the blocks within the same page. Is there a way we can validate if a block's property is unique across a page? for ex: a buttons ID, to ensure that the ID is not duplicated in the same page. This will help the editors from giving duplicate ID's while rendering the page.

Jul 13, 2020 14:50

Hi Anish,

Why you want this id value from content editor?

I think you can generate random id in your code while rendering the blocks.

Jul 13, 2020 16:53

This is required to track the GTM click ID for analytcs and other purposes like A/B testing.

Jul 13, 2020 17:04

You can use the IValidate<T> (example IValidate<ContentPage>) and inside that access your content area and blocks added into that. See below link for summarised code to add validation for the blocks added on a page.

Let me know if you need further help.


Jul 14, 2020 7:17

Thanks for replying. I am using a button block which is used in multiple other blocks. I need to ensure that the ID field in button block is unique within a page. For that I need to get all the button blocks within the current page from all its children and then perform the validation. This may sound strange but there is a requirement to provide the editors the option to give button ID's. Also, the page can have multiple content areas like heading content, main content and side content, so this becomes bit complex.

Jul 14, 2020 10:52

I know I am late to the party for this one, but one thing you could do is append a value to the id in the razor view to make it unique.

Simple thing might be to pass an int to the partial view, or use a DateTime.Tick.

I have used this successfully on a client site.

Feb 07, 2023 17:55
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.