Back to Devexpress

Passing Values to a Controller Action through Callbacks

aspnetmvc-9941-common-features-callback-based-functionality-passing-values-to-a-controller-action-through-callbacks.md

latest7.1 KB
Original Source

Passing Values to a Controller Action through Callbacks

  • Jul 12, 2023
  • 2 minutes to read

When a DevExpress MVC extension works in callback mode and requests the server via its own callback, you can use this callback to pass custom values collected on the client for further server processing. On the server side, you can process these values within a Controller action that is specified by the extension’s CallbackRouteValues property. Depending upon the passed values, you can conditionally form the response to be sent back to the client.

By design, a callback (initiated by a DevExpress MVC extension) automatically passes values to the server. These are specific extension-related values, and the values of all internal form elements (e.g., input, textarea, select) rendered inside our extensions. To pass custom values from the client via a callback, you should handle an extension-specific BeginCallback client event. This event’s argument provides you with the MVCxClientBeginCallbackEventArgs.customArgs property. This property represents a hash table object that can contain named values. Any named value assigned to the customArgs property is then passed to the server as a request parameter. On the server side, it can be accessed as a parameter of the specified Action. So, the necessary server-side actions can be performed in the handling Action based upon the value(s) passed from the client.

View:

javascript
function OnBeginCallback(s, e) {
        e.customArgs["Value1"] = 1;
        e.customArgs["Value2"] = 2;
    }

Controller:

csharp
public ActionResult MyView(int value1, int value2) {
        ...
    }

The following table lists DevExpress MVC extensions that expose the BeginCallback client event.

ExtensionEvent
BinaryImageMVCxClientBinaryImage.BeginCallback
CalendarMVCxClientCalendar.BeginCallback
CallbackPanelMVCxClientCallbackPanel.BeginCallback
CardViewMVCxClientCardView.BeginCallback
ChartMVCxClientChart.BeginCallback
ComboBoxMVCxClientComboBox.BeginCallback
DataViewMVCxClientDataView.BeginCallback
DockPanelMVCxClientDockPanel.BeginCallback
DocumentViewerMVCxClientGlobalEvents.BeginCallback
FileManagerMVCxClientFileManager.BeginCallback
GridViewMVCxClientGridView.BeginCallback
HtmlEditorMVCxClientHtmlEditor.BeginCallback
ImageGalleryMVCxClientImageGallery.BeginCallback
ListBoxMVCxClientListBox.BeginCallback
NavBarMVCxClientNavBar.BeginCallback
QueryBuilderMVCxClientQueryBuilder.BeginCallback
PageControlMVCxClientPageControl.BeginCallback
PivotGridMVCxClientPivotGrid.BeginCallback
PopupControlMVCxClientPopupControl.BeginCallback
ReportDesignerMVCxClientReportDesigner.BeginCallback
RichEditASPxClientRichEdit.BeginCallback, no customArgs property
RoundPanelMVCxClientRoundPanel.BeginCallback
SchedulerMVCxClientScheduler.BeginCallback
SchedulerStorageControlMVCxClientSchedulerStorage.BeginCallback
SpreadsheetMVCxClientSpreadsheet.BeginCallback
TokenBoxMVCxClientTokenBox.BeginCallback
TreeListMVCxClientTreeList.BeginCallback
TreeViewMVCxClientTreeView.BeginCallback
VerticalGridMVCxClientVerticalGrid.BeginCallback

For an example of how to pass and process client values, refer to the following online demo: Callback Panel - Example.

GitHub Example

View Example: How to Get All GridView Selected Keys and Pass Them to a Controller

See Also

Callback-Based Functionality