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

Passing parameters to the grid create action

8 Answers 1351 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 28 Aug 2015, 02:49 AM

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

Sort by
0
eo
Top achievements
Rank 1
answered on 28 Aug 2015, 03:41 PM

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!

0
Jeff
Top achievements
Rank 1
answered on 28 Aug 2015, 04:30 PM
I have a details view with two child grids at the bottom.  I am trying to figure out how I get the CustomerId (basically the Customer who's details are being viewed) in the CustomerId cell when I click "Create new record" on the CustomerClass grid.  I hope that makes sense.
0
Boyan Dimitrov
Telerik team
answered on 31 Aug 2015, 12:03 PM

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jeff
Top achievements
Rank 1
answered on 01 Sep 2015, 12:28 PM
Ok I have a details screen (Asp.net MVC Application....1st attachment) that is passing in the CustomerId.  When the user clicks on "Add new record" button in the Customer Class Child grid.  I want that CustomerId to appear in Customer Column (2nd attachment) in the grid (instead of having to manually type it in) and I have done this outside of the grids without any issues.  I am just trying to figure out how to make the CustomerId appear in the Customer column when I click "Add new record".  Let me know if you need a better explanation.
0
Boyan Dimitrov
Telerik team
answered on 03 Sep 2015, 09:14 AM

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jeff
Top achievements
Rank 1
answered on 04 Sep 2015, 06:37 PM
None of these answers has helped so far
0
Accepted
Boyan Dimitrov
Telerik team
answered on 07 Sep 2015, 02:19 PM

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jeff
Top achievements
Rank 1
answered on 09 Sep 2015, 01:47 PM
I had to use route values instead of CustomerId
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
eo
Top achievements
Rank 1
Jeff
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or