Controller.Active Property
Provides access to a collection of reason/value pairs used to activate or deactivate a Controller, or determine its active state.
Namespace: DevExpress.ExpressApp
Assembly: DevExpress.ExpressApp.v24.1.dll
NuGet Package: DevExpress.ExpressApp
Declaration
Property Value
Type | Description |
---|---|
BoolList | A BoolList object that represents a collection of key/value elements. |
Remarks
A Controller’s active state may depend on many factors such as the current view or user permissions. Any individual factor can prevent activation.
The Active
property stores the collection of factors that affect the active state. Each element of this collection contains a string value (factor description) and the corresponding Boolean value that permits or prohibits activation. If all collection elements are true
, the Controller is active.
The following methods allow you to determine whether a Controller is currently active:
- Use the
Active
property value in a conditional expression. - Read the
Active
property value. Use the return object’s BoolList.ResultValue property.
MyViewController myController;
//...
BoolList activeList = myController.Active;
if (activeList) {
//...
}
To deactivate a Controller, use the following members of the BoolList
object (Active
property value):
- Call the BoolList.SetItemValue method. Pass the reason for deactivation as the first parameter. Set the second parameter to a Boolean expression or simply to
false
. - Use the
[_key_]
operator to get or set the specified key’s value.
MyViewController myController;
//...
BoolList activeList = myController.Active;
activeList["myKey"] = false;
The following members can activate an inactive Controller:
- Call the BoolList.RemoveItem method. Pass the key (factor description). If the collection no longer contains any
false
values, the Controller becomes active. - Call the BoolList.SetItemValue method. Pass a factor description and ‘true’ as the corresponding value.
MyViewController myController;
//...
BoolList activeList = myController.Active;
activeList["disablingKey"] = true;
To activate or deactivate an Action instead of the entire Controller, use the Action’s ActionBase.Active property.
Deactivate a Built-In Controller
You may want to disable a built-in controller. Do this to disable features that you do not wish to use or if the controller’s logic conflicts with your business logic. You can choose one of the following techniques to achieve this.
Create a new Controller
In the new controller’s overridden
OnFrameAssigned
method, find the controller that you want to disable and use itsActive
property to deactivate the controller:using DevExpress.ExpressApp; using DevExpress.ExpressApp.SystemModule; public class DisableRecordsNavigationController : ViewController { protected override void OnFrameAssigned() { base.OnFrameAssigned(); var recordsNavigationController = Frame.GetController<RecordsNavigationController>(); if (recordsNavigationController != null) { recordsNavigationController.Active["Explicitly disabled"] = false; } } }
When you deactivate a controller this way, you can target the controller’s base type even if it has platform-specific descendants (RecordsNavigationController has an ASP.NET Core Blazor-specific
BlazorRecordsNavigationController
descendant). However, this method is not suitable if the controller has some undesirable logic in its ownOnFrameAssigned
override. In that case, use the following method.Inherit from the built-in Controller
Create a descendant of the built-in controller and deactivate it in the
OnFrameAssigned
method:using DevExpress.ExpressApp.Blazor.SystemModule; public class CustomRecordsNavigationController : BlazorRecordsNavigationController { protected override void OnFrameAssigned() { // keep the line below commented out to disable the base controller's OnFrameAssigned logic //base.OnFrameAssigned(); Active["Explicitly disabled"] = false; } }
In this case, you need to specify the platform-specific descendant of the controller you want to deactivate as your custom controller’s base class. This technique gives you more control over specifying when the controller should be active.
Note
If you deactivate a controller in the OnFrameAssigned
method, it disables the controller entirely. If you want to deactivate this controller in specific views, refer to the following topic: Define the Scope of Controllers and Actions - Activate or Deactivate a Controller.
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Active property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.