This is a migrated thread and some comments may be shown as answers.

How to Pass Additional Data to Create/Update/Destroy Action Method

8 Answers 1250 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chevron Phillips Chemical Co
Top achievements
Rank 1
Chevron Phillips Chemical Co asked on 24 Apr 2014, 04:34 PM
The documentation at http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/ajax-binding#pass-additional-data-to-the-action-method shows how to pass additional data to the Read action, when asynchronously binding the grid using AJAX.

Is there similar functionality available to other AJAX action methods Create, Update and Destroy?  I do not see any mention in the documentation at http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/ajax-editing.

8 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 25 Apr 2014, 11:40 AM
Hello,

The approaches mentioned in the documentation are not limited to the read action. The same could be used for the Create/Update/Destroy actions too.

Let me know if this information helps or I could assist you further.

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Chevron Phillips Chemical Co
Top achievements
Rank 1
answered on 25 Apr 2014, 01:30 PM

Could I ask you to review my implementation below?  For some reason I am receiving the client data in the Read action but not the Create action.

@(Html.Kendo().Grid<GridViewModel>()
   .DataSource(dataSource => dataSource
      .Ajax()
      .Read(read => read.Action("Read", "Controller").Data("getClientDataModel"))
      .Create(create => create.Action("Create", "Controller").Data("getClientDataModel"))
  
function getClientDataModel() {
   var queryStringParameters = getQuerystringParameters();
   return {
       Data: 1
   };
}
  
  
public ActionResult Read([DataSourceRequest] DataSourceRequest request, ClientDataModel clientData)
{
   // clientData.Data = 1
}
  
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([DataSourceRequest] DataSourceRequest request, GridViewModel model, ClientDataModel clientData)
{
   // clientData.Data = 0 (Int32 default)
}
  
public sealed class ClientDataModel
{
    public Int32 Data { get; set; }
}

 

0
Chevron Phillips Chemical Co
Top achievements
Rank 1
answered on 25 Apr 2014, 01:48 PM

I should also provide the definition for the GridViewModel class.  Note the field name "Data" is also used here.  Could that be a problem?

public sealed class GridViewModel
{
   public Int32 Data { get; set; }
}
0
Dimiter Madjarov
Telerik team
answered on 28 Apr 2014, 11:29 AM
Hello,


The implementation below looks correct. You could place a debugger statement in the JavaScript function to assure that it is being called and also inspect the Network tab of your browsers developer tools to check the Form Data that is being sent.

If the problem is still persisting, please send us a small separate isolated example with the Grid inside, in which the issue is reproducing, so we could inspect it locally and assist further.

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Chevron Phillips Chemical Co
Top achievements
Rank 1
answered on 28 Apr 2014, 06:53 PM
As it happens, there cannot be a field name (e.g. "Data") duplication between the grid's view model (e.g. "GridViewModel") and the client-side data model.  Not sure if this is happening at the javascript, MVC or Telerik layer.  The solution was to change the client-side data model's field name to be different that the field name in the grid's view model.

Another solution that seems to work for Create action is to set the default value of the field.

.DataSource(dataSource => dataSource
  .Ajax()
  .Model(model => {
    model.Field(x => x.Data)            // Set default value for grid model field
      .DefaultValue(Model.DefaultData); // as provided by controller in view model.
})
0
Dimiter Madjarov
Telerik team
answered on 29 Apr 2014, 08:37 AM
Hello,


Thank you for the additional details. I am glad that the issue is resolved. Indeed there cannot be a duplicate, because the MVC model binder could not be aware which of the two fields corresponds to the Model and which to the additional data object.

Do not hesitate to contact us if there are any further issues.

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Pavel
Top achievements
Rank 1
answered on 03 Sep 2017, 04:04 AM

Hi, got the same issue.. I don't understand though why binder could not differentiate e.g. I had

public ActionResult AddImage([DataSourceRequest] DataSourceRequest request, ImageListItem image, Client_ProductData productData)

 

where both ImageListItem and Client_ProductData had the same field ProductId.. in this case Client_ProductData.ProductId was always null, once I changed it to C_ProductId it started to work. Although these are two different objects.. So does it mean that any additional data (object) cannot have the same property as grid Model?

Thanks

Pavel

0
Stefan
Telerik team
answered on 05 Sep 2017, 10:15 AM
Hello Pavel,

This is expected as described by Dimiter "the MVC model binder could not be aware which of the two fields corresponds to the Model and which to the additional data object".

This is an MVC specific behaviour and it is not directly related to how Kendo UI is processing the data and the requests.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Chevron Phillips Chemical Co
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Chevron Phillips Chemical Co
Top achievements
Rank 1
Pavel
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or