Hi,
In order to hide the ID property from edit mode, there are two things you need to do.
First, to hide in from the create/edit template, simply add the ScaffoldColumn(false) attribute as you've already did.
Second, to hide it from the table, you'll need to add a custom editor descriptor and tell the editor to exclude the ID column. Here's an example:
public class MyCustomCollectionEditorDescriptor : CollectionEditorDescriptor<Question> { public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes) { this.GridDefinition.ExcludedColumns.Add(nameof(Question.Id)); base.ModifyMetadata(metadata, attributes); } }
Hope that helps!
As for creating a new ID when creating a new object, you could simply add a backing field and assign a new value in the getter:
private string _id; [ScaffoldColumn(false)] public string Id { get { if (string.IsNullOrEmpty(_id)) _id = Guid.NewGuid().ToString(); return _id; } set { _id = value; } }
Thank you Per Magne,
This is exactly what I'm looking for and this codes work great :)
I can´t get this to work unfortunately. Not sure if I´m missing something or if it´s no longer working for later version of CMS (we´re running 10.9.0).
I have a page type called StartLandingPage. There I have a property of type PropertyList, it looks like this:
[EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<IntegrationToolModel>))] public virtual IList<IntegrationToolModel> ToolIntegrationTabs { get; set; }
I then have an EditorDescriptor class that looks like this:
public class IntegrationToolEditorDescriptor : CollectionEditorDescriptor<IntegrationToolModel> { public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes) { GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.ApiUrl)); GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.HideOnDesktop)); GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.HideOnMobile)); GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.FormResult)); GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.CountryCode)); GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.DestinationUrl)); GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.ResultPage)); base.ModifyMetadata(metadata, attributes); } }
Where I specify a bunch of properties of IntegrationToolModel object that I don´t want to show in the table view. But it´s not working, they are not hidden from the view.
What am I missing or doing wrong?
I know this is an older post, but just in case someone is having the same issue like Petra, you need to:
The updated code would look like this:
public virtual IList<IntegrationToolModel> ToolIntegrationTabs { get; set; } [EditorDescriptorRegistration(TargetType = typeof(IList<IntegrationToolModel>))] public class IntegrationToolEditorDescriptor : CollectionEditorDescriptor<IntegrationToolModel> { public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes) { GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.ApiUrl)); GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.HideOnDesktop)); GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.HideOnMobile)); GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.FormResult)); GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.CountryCode)); GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.DestinationUrl)); GridDefinition.ExcludedColumns.Add(nameof(IntegrationToolModel.ResultPage)); base.ModifyMetadata(metadata, attributes); } }
Hi guys,
Since EPiServer 9, they support PropertyList in model, I wonder how I can hide some property from table?
In example, there are QuestionListPage and question class, I implement code like below. Now, I want to hide Id property in Question class from Editmode (from both display table and create/edit dialog). How can I hide it?
I also try to add [ScaffoldColumn(false)] or [Ignore] on top of Id property but Id can only hide in create/edit dialog, not hide in displaytable.
Another question is how can I create new GUID string value and add to Id when a question has been created?
Thanks,
Linh