0
votes

I'm looking at an example form the demo website of kendo http://demos.kendoui.com/web/grid/editing-custom.html

In the asp mvc code sample there is absolutely no reference to ViewData["categories"] from the controller.

Which black magic is it using to get this data in a dropdownlist in the editor?

1

1 Answers

2
votes

here as shown in below section they are providing datasource path direct to database and it fetches the value from the database so no magic there everything is using basic code laungage

dataSource: {
               type: "odata",
               transport: {
                     read: "http://demos.kendoui.com/service/Northwind.svc/Categories"
                          }
             }

and for MVC

var categories = dataContext.Categories
                        .Select(c => new ClientCategoryViewModel {
                            CategoryID = c.CategoryID,
                            CategoryName = c.CategoryName
                        })
                        .OrderBy(e => e.CategoryName);
            ViewData["categories"] = categories;
            ViewData["defaultCategory"] = categories.First();  

and for MVC view :-

.Model(model =>
        {
            model.Id(p => p.ProductID);
            model.Field(p => p.ProductID).Editable(false);
            model.Field(p => p.Category).DefaultValue(
                ViewData["defaultCategory"] as Kendo.Mvc.Examples.Models.ClientCategoryViewModel);
        })