Developer Docs - 303 - Blast Off - Attributes
Attributes are one of the secrets to Rock's amazing capability. Pretty much anything in Rock can have an attribute -- and you can add them at runtime or bake them into your code.
Adding Attribute Viewing/Editing Capabilities (the Attribute Value Container)
If you have a block that handles a particular entity which may have attributes, you can use the AttributeValuesContainer to quickly add view and edit capability to the block.
On View
connectionRequest.LoadAttributes();
avcAttributesReadOnly.AddDisplayControls( connectionRequest, Rock.Security.Authorization.VIEW, this.CurrentPerson );
On Edit
device.LoadAttributes();
avcAttributes.AddEditControls( device );
...or
// to exclude attributes due to security:
avcAttributes.AddEditControls( campus, Rock.Security.Authorization.EDIT, CurrentPerson );
On Save
avcAttributes.GetEditValues( device );
// Put these two saves in one transaction
rockContext.WrapTransaction( () =>
{
rockContext.SaveChanges();
device.SaveAttributeValues();
} );