Not able to make Umbraco Block Grid readonly or hi...
# help-with-umbraco
s
Hi, I am new to the Block Grid and lists, and I encountered an issue when trying to make Block Grid readonly. I have Block Grid Property which I want to hide for some user groups. I tried same hack that I have been doing forever (making the property readonly) but this results in error when saving the content. This is how I am trying to make it readonly:
Copy code
public class EditorSendingContentNotificationHandler : INotificationHandler<SendingContentNotification>
{
    private readonly IBackOfficeSecurityAccessor _backOfficeSecurity;

    public EditorSendingContentNotificationHandler(
        IBackOfficeSecurityAccessor backOfficeSecurity)
    {
        _backOfficeSecurity = backOfficeSecurity;
    }
public void Handle(SendingContentNotification notification)
    {
        if (notification.Content.ContentTypeAlias.Equals("mygrid"))
        {
            if(!( _backOfficeSecurity?.BackOfficeSecurity?.CurrentUser.Groups.Any(x=>x.Alias.Equals("admin")))){
                    makeBlockGridReadOnly(notification.Content, new List<string>{"blocks", "testblock"});
                   }
        }

private void makeBlockGridReadOnly(ContentItemDisplay contentItemDisplay, List<string> propertyAlias)
{
     if(propertyAlias.Any())
{
foreach(var tab in contentItemDisplay.Variants.FirstOrDefault().Tabs)
{
foreach(var prop in tab.properties)
{
if(propertyAlias.Contains(prop.Alias) && prop.View.Contains("blockgrid"))
{
     prop.Readonly = true;
}
}
}
}
}
https://cdn.discordapp.com/attachments/1260917308587638804/1260917308780449813/Blockgrid.png?ex=66911041&is=668fbec1&hm=194519dc5ae8aaa5065f81637c78ff2de51f7c315a7a89b97b17d051acfabc6c&
Hello @User , has anyone seen this?
j
Hi Sam, please don't ping the Moderator role unless you believe someone is violating the code of conduct 🙂 This is a community driven server and if someone is able to help you, then they will definitely respond!
8 Views