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

Passing a view model as parameter to Ajax grid Methode.

2 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ESSRIDI
Top achievements
Rank 1
ESSRIDI asked on 26 Mar 2011, 07:28 PM

Is it possible to do this ? 
  
View 
Html.Telerik().Grid(Model.listPerson)
         .Name("aGrid")
         .Pageable( paging =>
            paging.PageSize(10) )

 .DataBinding(dataBinding => dataBinding.Ajax().Select(
    "FindPerson", "Person", new {  searchvm= Model.SearchCriteriaVM }))
         .Columns(columns =>
         {
       
             ......


Controller 

  [GridAction]


        public ActionResult _ListPerson(SearchVM  searchvm )
        {
          List<Person> listp  = ServicePerson.get(searchvm ).ToList();
       
            return PartialView("_ListPerson", new GridModel<List<Person>>
            {
                Data = listp
            });
           
        }

If it's not possible ( and that what I think ) is there any others solutions to do it ?


Thanks,
Salmen



2 Answers, 1 is accepted

Sort by
0
Nate
Top achievements
Rank 1
answered on 05 May 2011, 12:42 PM
Did you solve this problem? I have the a similar issue. It is sad that no one has replied back to you.
0
ESSRIDI
Top achievements
Rank 1
answered on 06 May 2011, 12:24 AM
Hi nate,  I solve my problem by passing my items one by one  on the  "OnDataBinding" client  event.So the  solution can be like this  : 
View 

.....
Html.Telerik().Grid(Model.listPerson)
         .Name("aGrid")
         .Pageable( paging =>
            paging.PageSize(10) )
      .ClientEvents(events => events.OnDataBinding("onDataBinding"))
 .DataBinding(dataBinding => dataBinding.Ajax().Select( "FindPerson", "Person"))
         .Columns(columns =>
         {
       
             ......

<script type="text/javascript">

    function onDataBinding(e) {
 
        e.data = { Name : $('#Name').val() , Firstname : $('#FirstName').val() };
    }


</script>


my ViewModel 



    public class SearchVM  
    {  
        public string Name{ get; set; }
        public string Firstname  { get; set; }
....
    }



Controller 

  [GridAction]

//now the items should be passed  into searchvm 

        public ActionResult _ListPerson(SearchVM  searchvm )
        {
          List<Person> listp  = ServicePerson.get(searchvm ).ToList();
       
            return PartialView("_ListPerson", new GridModel<List<Person>>
            {
                Data = listp
            });
           
        }

I hope that can help you 



Tags
Grid
Asked by
ESSRIDI
Top achievements
Rank 1
Answers by
Nate
Top achievements
Rank 1
ESSRIDI
Top achievements
Rank 1
Share this question
or