[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Collapse]eXpressApp Framework
 [Expand]Getting Started
 [Expand]Design-Time Features
 [Collapse]Task-Based Help
  [Expand]Business Model Design
  [Expand]Application Model
    How to: Add a Search Action to Lookup Property Editors and Link Pop-up Windows
    How to: Add the Analyze Action to List Views
    How to: Create an Action Using the Action Attribute
    How to: Customize Action Controls
    How to: Customize the Export Action Behavior
    How to: Customize the New Action's Items List
    How to: Deactivate (Hide) an Action in Code
    How to: Disable an Action When the Current View Has Unsaved Changes
    How to: Hide the Edit Action Column from a ListView in an ASP.NET Application
    How to: Initialize an Object Created Using the New Action
    How to: Limit the Amount of Objects Created using the New Action
    How to: Make the FullTextSearch Action Search Within Required Properties
    How to: Reorder an Action Container's Actions Collection
    How to: Replace a List View's Default Action
  [Expand]List Editors
  [Expand]Property Editors
  [Expand]Scheduler and Notifications
  [Expand]Maps Module
  [Expand]Miscellaneous UI Customizations
  Frequently Asked Questions (FAQ)
 [Expand]API Reference
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Create an Action Using the Action Attribute

This example demonstrates how to create an Action within a persistent class declaration (i.e., how to convert a persistent class method into a SimpleAction or PopupWindowShowAction).


A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E3884.


Expanded Create A Simple Action

Let us start with the following Task business class.

Assume that implementing an Action that changes the IsCompleted value to true is required. Add the following Complete method to the Task class and decorate it with the ActionAttribute attribute.

Such methods are automatically collected from business classes by the ObjectMethodActionsViewController Controller. This controller will create the Task.Complete Action, which will invoke the Complete method for each selected Task. Note the use of the ActionAttribute.TargetObjectsCriteria parameter. The Action will be disabled for Tasks that are already completed (the IsCompleted property is true). You can pass other parameters to customize the Action's look and behavior. The image below illustrates the Complete Action in the UI.

Expanded Create an Action that Displays the Pop-up Dialog

Next, extend the Task class demonstrated in the previous section of this topic with several additional properties to demonstrate a more complex scenario. Here are these properties (Deadline and Comments).

Assume that you are required to implement an Action that postpones the Deadline for a specified number of days and updates the Comments text. First, implement the following non-persistent class that declares parameters to be specified when an end-user postpones a Task.

Then, add the following Postpone method to the Task class. This method takes a parameter of the PostponeParametersObject type and is decorated with the Action attribute.

As a result, the Task.Postpone Action, which accompanies the Task Views, will be automatically created. This Action invokes a dialog with the PostponeParametersObject Detail View and executes the Postpone method after an end user specifies the parameters and clicks OK. The following images illustrate this.


If there is a requirement for reordering parameters displayed in a popup dialog, modify the layout of a parameter object's Detail View in the Model Editor. In the example above, the appropriate Detail View node is PostponeParametersObject_DetailView. Refer to the View Items Layout Customization topic to learn more about layout customizations.

Access the current object instance

If you declare a PostponeParametersObject constructor that takes a parameter of a target business objects' type (Task), the current Task instance will be passed to this constructor when the Action is executed.

Is this topic helpful?​​​​​​​