Hello.
I am using the following:
Asp.net MVC 5
Ajax binding
Inline Editing
I need to pass a value to to the grid so it is populated automatically (see attached screenshot). I have google'd looked at these forums, but the following doesn't seem to populate the value in the grid.
.Read(read => read.Action("CustomerClass_Read", "CustomerClass").Data("{ CustomerId: " + @Model.CustomerId + "}"))
I know how to do this with through an Actionlink:
@Html.ActionLink("New", "Create", "ShipTo", new { CustomerId = Model.CustomerId }, new { @class = "btn btn-default btn-sm" })
Please advise.
Thanks
8 Answers, 1 is accepted
Hello Jeff,
The read.Action() method can receive a third parameter that is an object of routeValues. To send a CustomerId of 5 for example, you can just use:
.Read(read => read.Action(
"CustomerClass_Read"
,
"CustomerClass"
,
new
{ CustomerId = 5 })
Hope this helps!
Hello Jeff,
Could you please elaborate a bit more on your scenario?
Create new record" is a button within the child grid and you are trying to access the parent row model? If so - please review the solution provided in the forum thread.
Regards,
Boyan Dimitrov
Telerik
Hello Jeff,
I would suggest you to use the edit event of the child grid in the details screen. The event arguments does have e.model so you can use its isNew method to check if the data item is new (created) or not (edited). the model's set method could be used in order to set the Customer field value.
Please refer to How can I get query string values in JavaScript? to get the customer value.
Regards,
Boyan Dimitrov
Telerik
Hello Jeff,
As far as I understand you want to set a value for the CustomerId field when creating a new record. I would suggest the following:
1. Use the Kendo UI Grid edit event, which is fired when the user edits or creates a data item.
2. In order to determine whether user is editing an existing item or creating a new one you can use the mode isNew method as described in the article.
3. Use the model set method in order to set the new value for a field of the model.
e.model.set(
"CustomerId"
, value)
Regards,
Boyan Dimitrov
Telerik