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

DropDownList in Partial using DataSource.Read

4 Answers 215 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Cool Breeze
Top achievements
Rank 1
Cool Breeze asked on 28 Mar 2014, 06:20 PM
I have several grids that I use to maintain records in tables. Several of these have a foreign key where I use a DropDownList to allow the user to select a name from the list rather than an ID. I have gotten all of this working great by using your examples. I basically have a UIHint on my property that specifies the partial view to use when editing/adding and item and I have partial views defined.

Like I said, everything is working great if I follow your examples and bind the DropDownLists to a collection in ViewData by using the .BindTo property on the DDL. Now I am trying to get away from using ViewData and I changed it to bind by using DataSource.Read and passing a controller and action but now there are no items in the list when I go to edit. The controller method is getting hit and results are being returned, it just never looks like anything actually gets loaded into the dropdown.

Here is my partial view with the DropDown:

@(
 Html.Kendo().DropDownListFor(m => m) 
    .Name("Department")
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("GetDepartments", "DepartmentMaintenance");
        });
    })
    .DataValueField("DepartmentId")
    .DataTextField("DepartmentName")
)

And here is my controller method:

//
// GET: /DepartmentMaintenance/GetDepartments
public ActionResult GetDepartments([DataSourceRequest]
                                DataSourceRequest request)
{
    var bll = new CatalogMaintenanceBll();
    var departments = bll.GetDepartmentList(false);
 
    return Json(departments.ToDataSourceResult(request));
}

It is making it into the controller method and departments does have items in it.

Can anyone see anything obviously wrong or know of anything that might cause this behavior?

Thank you!






4 Answers, 1 is accepted

Sort by
0
Cool Breeze
Top achievements
Rank 1
answered on 28 Mar 2014, 06:28 PM
I noticed I had forgot to change DropDownListFor to DropDownList() so I made that change, didn't fix my issue though.
0
Cool Breeze
Top achievements
Rank 1
answered on 28 Mar 2014, 06:45 PM
Ok so I think I do still need the "DropDownListFor( m=> m.property). Here is another example:

@model Common.Models.Zone
      
@(
 Html.Kendo().DropDownListFor(m=> m.Page)
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("GetPages", "PageMaintenance");
        });
    })
     .DataValueField("PageId")
     .DataTextField("PageName")
     )

It is being called by (Model is of type Zone):
@{Html.RenderPartial("_PageSelectorPartial", Model);}

Same result. Controller method gets called, returns data but the DropDownList will never open or there is nothing in it.














0
Alexander Popov
Telerik team
answered on 01 Apr 2014, 12:13 PM
Hello,

I noticed that GetDepartments is using the ToDataSourceResult method before sending the data to the client. This will modify the data structure and the DropDownList will not recognize it, as mentioned here, so I would recommend removing the ToDataSourceResult method.

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
Cool Breeze
Top achievements
Rank 1
answered on 04 Apr 2014, 02:28 PM
Thank you Alexander, I will certainly give that a try. I think I started out without that but ended up changing it to try and get something to work. I could be wrong though so I'll go back and try and let you know what happens. Thanks for the suggestion!
Tags
DropDownList
Asked by
Cool Breeze
Top achievements
Rank 1
Answers by
Cool Breeze
Top achievements
Rank 1
Alexander Popov
Telerik team
Share this question
or