Read querystring from kendo grid not passing to parameter in controller action

6 posts, 1 answers
  1. Bharathi
    Bharathi avatar
    16 posts
    Member since:
    Feb 2014

    Posted 07 Mar 2014 Link to this post

    Kendo Grid with url takes to another kendo grid

    I'm stuck with reading the querystring value from grid1 url to grid2 controller.. Any help appreciated..

    Grid1

    Index.cshtml
      columns.Bound(e => e.TCBSTAGE).Width(100).ClientTemplate("<a href='/" + "ControllerName" + "/Index?Batchno=#=BatchNo#'>#=TCBSTAGE#</a>");



    Grid2Index.Cshtml

    <script>$(function(){
       $("#grid").kendoGrid({
      dataSource: {
        transport: {
          read: {  
             url: "ControllerName2/GetRecords",
             contentType: "application/json",
             type: "POST"
          },
          parameterMap: function (options) {       
            return kendo.stringify(options);
          }
        },
        schema: {
          data: "Data",
          total: "Total"
       
        },
        pageSize: 10,
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true
      },
      groupable: true,
      filterable: true,
      sortable: true,
      pageable: true,
      columns: [
     { field: "BatchNo", title: "BatchNo" },
     { field: "Fiscal_Year ", title: "Fiscal_Year" },
     { field: "Department", title: "Department" }
      ]
    });
    });</script>


    Grid 2 controller.. I need to get the Batchno value here

    ControllerName2.cs

      [HttpPost]
            public ActionResult GetRecords(int take, int skip, IEnumerable<Kendo.DynamicLinq.Sort> sort, Kendo.DynamicLinq.Filter filter)
            {
                //Batchno from grid1 url
               I need the querystring id from grid1 here....          }


    Any Help appreiciated. Thank you
  2. Answer
    Daniel
    Admin
    Daniel avatar
    2231 posts

    Posted 11 Mar 2014 Link to this post

    Hello,

    Since the script is used in the view, you can render the sent value in the script in order to send it e.g.
    <script>$(function(){
    $("#grid").kendoGrid({
      dataSource: {
        transport: {
          read: {  
             url: "ControllerName2/GetRecords",
             contentType: "application/json",
             type: "POST",
             data: {
                BatchNo: @Request["Batchno"]
             }
          },
          ...


    Regards,
    Daniel
    Telerik

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

  3. Bharathi
    Bharathi avatar
    16 posts
    Member since:
    Feb 2014

    Posted 11 Mar 2014 in reply to Daniel Link to this post

    Hi,

             Thanks for the answer.. but How do i read that BatchNo inside the action.... 

      [HttpPost]
            public ActionResult GetRecords( int take, int skip, IEnumerable<Kendo.DynamicLinq.Sort> sort, Kendo.DynamicLinq.Filter filter, HttpContextBase httpcontext)        
            {
     //read batchno here..
    }
  4. Bharathi
    Bharathi avatar
    16 posts
    Member since:
    Feb 2014

    Posted 11 Mar 2014 in reply to Daniel Link to this post

    Thanks It Works...

    [HttpPost]
            public ActionResult GetRecords(long BatchNo, int take, int skip, IEnumerable<Kendo.DynamicLinq.Sort> sort, Kendo.DynamicLinq.Filter filter)
            {
             
    var bno = BatchNo
    .          }
  5. Bharathi
    Bharathi avatar
    16 posts
    Member since:
    Feb 2014

    Posted 03 Apr 2014 in reply to Daniel Link to this post

    @* The DIV where the Kendo grid will be initialized *@
    <div id="grid"></div>
     
    <script>
     
        $(function () {
            $("#grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                          url: "GetTransctionDetails",
                          contentType: "application/json; charset=utf-8",
                          type: "POST",
                          cache: true,                     
                            data: {
                                    Period: @Request["Period"],
                                    AccCode: @Request["AccCode"],
                                    Fiscalyr: @Request["Fy"],
                                    Entity:@Request["entity"]
                                  }
                              },
     
                        parameterMap: function (options) {
                          return kendo.stringify(options);
                        }
                  },
                    schema: {
                        data: "Data",
                        total: "Total"                 
     
                    },
                    pageSize: 10,
                    serverPaging: true,
                    serverFiltering: true,
                    serverSorting: true
                },
                groupable: true,
                columnMenu: true,
                filterable: true,
                sortable: true,
                pageable: true,
                columns: [
     { field: "TRANSACTION_KEY", title: "BatchNo", width: "100px" },
     { field: "FISCAL_YEAR ", title: "Fiscal_Year", width: "150px" },
     { field: "ACCOUNTING_PERIOD", title: "Department", width: "150px" }
     
       ]
            });
        });
     
    </script>

    Hi,

         In the above code the @Request["entity"] is throwing Uncaught Reference Error.... I'm passing string value for the entity... How do you call the parameter with string value... Please find the attached file for more details on the error.. 

    Thank you fo 
  6. Bharathi
    Bharathi avatar
    16 posts
    Member since:
    Feb 2014

    Posted 03 Apr 2014 in reply to Daniel Link to this post

    Please Ignore the previous post...

    I fixed it .....missed the quotes..

     data: {
                                    Period: @Request["Period"],
                                    AccCode: @Request["AccCode"],
                                    Fiscalyr: @Request["Fy"],
                                    Entity:"@Request["entity"]"
                                  }
Back to Top