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
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.
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; }
}
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; }
}
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.
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.
})
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.
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
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