Skip to main content
All docs
V23.2

Add a Simple Action Using an Attribute

  • 2 minutes to read

This lesson explains how to use methods of an entity class to add a Simple Action.

The instructions below show how to add a new method with the ActionAttribute attribute to the DemoTask class.

Note

Before you proceed, take a moment to review the previous lessons:

Step-by-Step Instructions

  1. Add the Postpone method to the DemoTask class:

    namespace MySolution.Module.BusinessObjects
    
    [DefaultClassOptions]
    [ModelDefault("Caption", "Task")]
    public class DemoTask : BaseObject {
        // ...
        /* Use this attribute to display the Postpone button in the UI
        and call the Postpone() method when a user clicks this button*/
        [Action(ToolTip = "Postpone the task to the next day", Caption = "Postpone")]
        // Shift the task's due date forward by one day
        public void Postpone() {
            if(DueDate == DateTime.MinValue) {
                DueDate = DateTime.Now;
            }
            DueDate = DueDate + TimeSpan.FromDays(1);
        }
    }
    

    Tip

    You can use the Action attribute to implement an action that asks a user to specify parameters in a popup dialog (for example, the number of days to postpone a Task). Refer to the following topic for an example: How to: Create an Action Using the Action Attribute.

  2. Run the application. Select the Task item in the navigation control.

    Select one or more tasks in the Task List View. This activates the Postpone Action button. Click this button to shift the due date of the selected tasks forward by one day.

    ASP.NET Core Blazor
    ASP.NET Core Blazor attribute action postpone
    Windows Forms
    Windows Forms attribute action postpone

Note

CodeRush allows you to add Actions and Controllers with a few keystrokes. To learn about the Code Templates for XAF, refer to the following help topic: XAF Templates.

Next Lesson

Add an Item to the Navigation Control

See Also