Passing parameters to the grid create action

9 posts, 1 answers
  1. Jeff
    Jeff avatar
    20 posts
    Member since:
    Jul 2015

    Posted 27 Aug 2015 Link to this post

    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

     

  2. eo
    eo avatar
    27 posts
    Member since:
    Jul 2015

    Posted 28 Aug 2015 in reply to Jeff Link to this post

    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!

  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Jeff
    Jeff avatar
    20 posts
    Member since:
    Jul 2015

    Posted 28 Aug 2015 in reply to eo Link to this post

    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.
  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 31 Aug 2015 Link to this post

    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
  6. Jeff
    Jeff avatar
    20 posts
    Member since:
    Jul 2015

    Posted 01 Sep 2015 in reply to Boyan Dimitrov Link to this post

    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.
  7. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 03 Sep 2015 Link to this post

    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
  8. Jeff
    Jeff avatar
    20 posts
    Member since:
    Jul 2015

    Posted 04 Sep 2015 Link to this post

    None of these answers has helped so far
  9. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 07 Sep 2015 Link to this post

    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
  10. Jeff
    Jeff avatar
    20 posts
    Member since:
    Jul 2015

    Posted 09 Sep 2015 in reply to Jeff Link to this post

    I had to use route values instead of CustomerId
Back to Top
UI for ASP.NET MVC is VS 2017 Ready