Is there a way to ignore a model property when posting to an action from a grid? Delete, create, update etc. The property needs to be loaded with the grid in the read action but not posted to the delete, create and update actions.
4 Answers, 1 is accepted
0
Hello Sebastian,
By default the entire Model will be submitted to the server when updating/creating/deleting an item. However, if you would like to prevent the users from editing a specific field you can configure the Editable setting for it in the DataSource Model configuration. The code would look similar to the following:
Let me know how this approach works for you.
Regards,
Viktor Tachev
Progress Telerik
By default the entire Model will be submitted to the server when updating/creating/deleting an item. However, if you would like to prevent the users from editing a specific field you can configure the Editable setting for it in the DataSource Model configuration. The code would look similar to the following:
.DataSource(dataSource => dataSource .Ajax() .Model(model => { model.Id(p => p.ProductID); model.Field(p => p.ProductID).Editable(false); model.Field(p => p.UnitPrice).Editable(false); }) .PageSize(20) .Create(update => update.Action("CreateAction", "Controller")) .Read(read => read.Action("ReadAction", "Controller")) .Update(update => update.Action("UpdateAction", "Controller")) .Destroy(update => update.Action("DestroyAction", "Controller")))Let me know how this approach works for you.
Regards,
Viktor Tachev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Eli
Top achievements
Rank 1
Veteran
answered on 28 Jan 2019, 04:14 PM
If the field is a complex object how would you keep it from being submitted to server or have it ignored? This type of data displays fine and I am able to update, however, if I add Create to the Grid it throws an "Uncaught ReferenceError: CreatedBy is not defined" I have tried a few ways to do this without any luck. The Add New Record button will not work. If I comment out the field it all works correctly. I only want this nested field for Read Display.
For instance if you have
.Columns(columns => { columns.Bound(c => c.CreatedBy.DisplayName);}.Model(model => { model.Field(c => c.CreatedBy.DisplayName).Editable(false);}0
Hi Eli,
When creating a new item in the Grid the respective editors would be populated with the defailt value for each field. However, when a field is an object the editor has no way of knowing what value should be applied to it.
In this case you can specify a default value for the field in the Schema Model configuration. The custom editor example below has a default value specified for the Category field.
Regards,
Viktor Tachev
Progress Telerik
When creating a new item in the Grid the respective editors would be populated with the defailt value for each field. However, when a field is an object the editor has no way of knowing what value should be applied to it.
In this case you can specify a default value for the field in the Schema Model configuration. The custom editor example below has a default value specified for the Category field.
Regards,
Viktor Tachev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Eli
Top achievements
Rank 1
Veteran
answered on 01 Feb 2019, 12:59 PM
Thanks Viktor, this helped me get it worked out.
