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

DropDownList dont show data with JSON

1 Answer 218 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Eduardo
Top achievements
Rank 1
Eduardo asked on 09 Jul 2013, 07:56 PM
i have a problem with a DropdownList control.
 i have a Grid with a popup edditing and when i show a popup the DropDownList doesnt show any data, im using MVC4 and KendoUI controls

this is the code.The Grid.

@(Html.Kendo().Grid<CashControl.Models.Usuario>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.nombre).Width(100);
columns.Bound(p => p.nombreUsuario).Width(100);
columns.Bound(p => p.email).Width(100);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("DropDownListUsuarios"))
.Pageable()
.Sortable()
.Scrollable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.idUsuario);
})
.Create(update => update.Action("EditingInline_Create", "Grid"))
.Read(read => read.Action("UsuariosRead", "Configuracion"))
.Update(update => update.Action("EditingInline_Update", "Grid"))
.Destroy(update => update.Action("EditingInline_Destroy", "Grid"))
)
)

The PopUp

<div class="demo-section" style="width: 250px;">
<h2>Products</h2>
@(Html.Kendo().DropDownList()
.Name("products")
.HtmlAttributes(new { style = "width: 250px" })
.DataTextField("nombre")
.DataValueField("idnombre")
.DataSource(source => {
source.Read(read =>
{
read.Action("UsuarioRead", "Configuracion");
});
})
)
</div>
<style scoped>
.demo-section {
width: 250px;
margin: 35px auto 50px;
padding: 30px;
}
.demo-section h2 {
text-transform: uppercase;
font-size: 1.2em;
margin-bottom: 10px;
}
</style>

and the Controller.

public ActionResult UsuarioRead([DataSourceRequest] DataSourceRequest request)
{
IQueryable<Usuario> products = CashControl.Usuario;
var rest = products.Select(n => new
{
idUsuario = n.idUsuario,
nombre = n.nombre,
nombreUsuario = n.nombreUsuario,
email = n.email
});

DataSourceResult result = rest.ToDataSourceResult(request);

return Json(result, JsonRequestBehavior.AllowGet);
}
and this is the JSON

result{"Data":[{"idUsuario":1,"nombre":"Eduardo","nombreUsuario":"Brakyo","email":"eduardomeji@gmail.com"}],"Total":1,"AggregateResults":null,"Errors":null}


1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 11 Jul 2013, 04:21 PM
Hello Eduardo,

The dropdownlist does not use the DataSourceResult and expects a collection e.g.

public ActionResult UsuarioRead()
{
    IQueryable<Usuario> products = CashControl.Usuario;
    var rest = products.Select(n => new
    {
        idUsuario = n.idUsuario,
        nombre = n.nombre,
        nombreUsuario = n.nombreUsuario,
        email = n.email
    });
 
    return Json(rest, JsonRequestBehavior.AllowGet);
}
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
DropDownList
Asked by
Eduardo
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or