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

Read method with "#" value as Parameter.

3 Answers 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dev2
Top achievements
Rank 1
Dev2 asked on 16 Jan 2014, 11:44 AM
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);
      }))

3 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 16 Jan 2014, 12:50 PM
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!
0
Dev2
Top achievements
Rank 1
answered on 17 Jan 2014, 05:34 AM

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);
      }))
0
Alexander Popov
Telerik team
answered on 20 Jan 2014, 01:21 PM
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!
Tags
Grid
Asked by
Dev2
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Dev2
Top achievements
Rank 1
Share this question
or