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

The Data option of the Read function not working in ListView

2 Answers 208 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 03 Jul 2013, 05:37 PM
I have a combobox and a list view on a page. When ever an item is selected in the combo box it is suppose to load the listview with items from a table with the selected criteria. No matter what the data is not passed to the read method in the controller

The View
@(Html.Kendo().ComboBox()
        .Name("reportTablesCombo")
        .HtmlAttributes(userControlAttributes)                            
        .DataTextField("Text")
        .DataValueField("Value")                            
        .DataSource(source =>
        {
              source.Read(read =>
        {
                     read.Action("BuildSelectList", "ProgramManager", new { list = "Tables" });
        });
 })
       .Events(e =>
      {
             e.Change("Combo_onChange");
      })
 )     
@(Html.Kendo().ListView(Model)
      .Name("fieldListView")
       .ClientTemplateId("template")               
       .TagName("div")
       .Editable()
      .DataSource(dataSource =>{
                   dataSource.Model(model => model.Id("AdminFieldId"));
                    dataSource.Read(read => read.Action("_Read", "ProgramManager").Data("GetTable"));
                    dataSource.PageSize(10);   
        })
        .Pageable()  
 )
The javascipt

function Combo_onChange(e) {
 
       listdata.dataSource.read();
   }
 
   function GetTable() {
       debugger;
       var table = (reportTablesCombo != null  ? reportTablesCombo.text() : "");
       return table;
   }

the Read method in the controller. I have the debugger going and it returns the proper string but when it is read in the controller the value is ALWAYS null.

What am I doing wrong here?
public ActionResult _Read([DataSourceRequest]DataSourceRequest request, string table)
{
     var results = appDb.AdminFields.Where(t => t.AdminTableName == table);      
     return Json(results.ToDataSourceResult(request));
 }

2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 04 Jul 2013, 06:52 AM
Hello Paul,

You should return the additional data as a object in order to be properly parsed on server. See the code snippets here for more details.

In your case it should be as follow:

function GetTable() {
 var table = (reportTablesCombo != null  ? reportTablesCombo.text() : "");
 return {
   table: table
  };
}

Regards,
Nikolay Rusev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Paul
Top achievements
Rank 1
answered on 08 Jul 2013, 12:02 PM
Nikolay,

Thank you very much, that did the trick

Paul
Tags
ListView
Asked by
Paul
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Paul
Top achievements
Rank 1
Share this question
or