- Define a custom button via the GridViewSettings.CommandColumn.CustomButtons collection;
- Customize the client-side CustomButtonClick event handler via the GridViewSettings.ClientSideEvents.CustomButtonClick property: pass the destination Url/Address (generated via the Url.Action helper method) as a parameter;
- Handle the client-side ASPxClientGridView.CustomButtonClick event;
- Retrieve the clicked row's keyValue via the client-side ASPxClientGridView.GetRowKey method. Use the EventArgs e.visibleIndex property as a parameter;
- Add the retrieved keyValue parameter to the specified destination Url;
- Navigate to the specified Url by changing the window.location.href property;
- Retrieve the passed keyValue via an argument of the invoked Action's parameter.
Question Comments
Added By: Sorin Sandu at: 4/28/2015 1:42:07 AM
On me s parameter is undefined.
What I am doing wrong ?
Hi Sorin,
To process your recent post more efficiently, I created a separate ticket on your behalf: T235581: Parameter is undefined when using a solution provided in the E4827 code example. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.
The parameters dictionary contains a null entry for parameter 'inventoryItemId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult ListnewItem(Int32)' in 'RecycleTracker.Controllers.SalesListingsController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
It appears that the 'key' value is not automatically assigned to the variable expected in the controller's function if it's not 'id'. This can be fixed in two ways, use the 'id' variable (which is set automatically) or provide the request variable name in the destUrl. I was able to fix it by changing the JScript destUrl to this:
var destUrl = url + "/?inventoryItemId=" + key;
Hope this helps someone that might be dealing with this.
Mike
Added By: Alessandro (DevExpress Support) at: 7/7/2016 9:18:44 AM
Hello,
I've created a separate ticket on your behalf (T400926: How to call an Action method via a custom button and pass a row's key as a parameter). It has been placed in our processing queue and will be answered shortly.