Read method with "#" value as Parameter.

4 posts, 0 answers
  1. Dev2
    Dev2 avatar
    3 posts
    Member since:
    May 2012

    Posted 16 Jan 2014 Link to this post

    Hi,

    I have kendo grid read parameterized method, which search employees. When I as search string with "#" than it does not search. When I debug the code and check searchName value in controller, it was empty. I also checked Json request using IE developer tool, it also remove # values from query string. 

    I have pasted my code below. Please guide me.

    1. Controller Read Method
    01.[HttpPost]
    02.public ActionResult ReadEmployee([DataSourceRequest] DataSourceRequest command,string searchName){
    03.var empList = GetEmployeeListByFirstAndLastName(searchName)
    04.var result = new DataSourceResult
    05.           {
    06.                Data = empList .FirstName,
    07.                Total = empList .LastName
    08.            };
    09.return Json(result,JsonRequestBehavior.AllowGet);
    2. Kendo Grid 
    @(Html.Kendo().Grid<EmployeeModel>()
         .Name("Grid")
         .DataSource(dataSource => dataSource
                           .Ajax()
                           .PageSize(20)
                           .Read(read => read.Action("ReadEmployee", "Home", "#"))
     )
          .Columns(columns =>
          {
                 columns.FirstName
         })
     
          .Sortable()
          .Scrollable(scrollable => scrollable.Height("auto"))
          .Resizable(resizing => resizing.Columns(true))
          .Pageable(pager =>
          {
              pager.Refresh(true);
              pager.Numeric(true);
          }))

  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1441 posts

    Posted 16 Jan 2014 Link to this post

    Hello,

    In the current scenario I would recommend passing the searchName string using the Data method. For example:  
    ...
    .Read(read=> read.Action("ReadEmployee", "Home").Data("onRead"))
    ...
      
    <script type="text/javascript">
        function onRead() {
            return {searchName: "Some # text"}
        }
    </script>


    Regards,
    Alexander Popov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Dev2
    Dev2 avatar
    3 posts
    Member since:
    May 2012

    Posted 16 Jan 2014 Link to this post


    It works on Above case. But it is not working in below case. In which I have to read Data for parameter from ViewData.

    Please suggest.
    [HttpPost]
    public ActionResult ReadEmployee([DataSourceRequest] DataSourceRequest command,EmployeeModel emp){
    var empList = GetEmployeeListByFirstAndLastName(emp.FirstName, emp.LastName)
    var result = new DataSourceResult
              {
              Data = empList .FirstName,
               Total = empList .LastName
              };
    return Json(result,JsonRequestBehavior.AllowGet);
    }
    @(Html.Kendo().Grid<EmployeeModel>()
          .Name("Grid")
          .HtmlAttributes(new { @class = "grid-16 EditGrid" })
          .DataSource(dataSource => dataSource
                                        .Ajax()
                                        .PageSize(20)
                                        .Read(read => read.Action("ReadEmployee", "Home", Html.AntiForgeryMvcTokenRouteValues("ReadEmployee").AddRouteValues(ViewData["EmployeeModel"])))
     )
          .Columns(columns =>
          {
    columns.FirstName
    })
     .Sortable()
          .Scrollable(scrollable => scrollable.Height("auto"))
          .Resizable(resizing => resizing.Columns(true))
          .Pageable(pager =>
          {
              pager.Refresh(true);
              pager.Numeric(true);
          }))
  4. Alexander Popov
    Admin
    Alexander Popov avatar
    1441 posts

    Posted 20 Jan 2014 Link to this post

    You could populate a hidden input element with the values coming from the ViewData and then use the approach I suggested in my previous reply. I am not exactly sure how the AntiForgeryMvcTokenRouteValues helper works, nevertheless you can check this example where AntiForgeryToken is used:
    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
        .Name("Grid")
        ...
        .DataSource(dataSource => dataSource
            ..
            .Read(read=> read.Action("Editing_Read", "Grid").Data("onRead"))
        )
    )
      
    @Html.AntiForgeryToken()
     
    <script type="text/javascript">
        function onRead() {
            //use a jQuery selector to get the value of the hidden input element
            return { token: $("[name=__RequestVerificationToken]").val(); }
        }
    </script>


    Regards,
    Alexander Popov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top