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

How to Migrate DropDownLists's DBContext to MVC5 using Latest UI for MVC bits

1 Answer 54 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Sid
Top achievements
Rank 1
Sid asked on 03 Feb 2015, 07:13 PM
Hi,

I'm migrating an MVC3 application to MVC5 which includes heavy use of the Kendo library.  My new solution includes the bits from UI for MVC.  I'm seeing an issue with defining the DBContext for a particular view.  My code is as follows:
01.var ctx = System.Web.HttpContext.Current.GetDataContext;
02. 
03.$jqInt("#to-country").kendoDropDownList({
04.            dataValueField: "id",
05.            dataTextField: "name",
06.            dataSource:$jqInt.merge([{ id:'', name:'Select Country'}], @Html.Raw(Json.Encode(ctx.AFCountries.Select(x => new { x.id, x.name })))),
07.            change: function(e){
08.                quote.set("toCountry", e.sender.value());
09.                $jqInt("#to-city").data("kendoDropDownList").dataSource.read();
10.            }
11.        });

Since I'm now using Entity Framework and have a Model AFCountry, what must I do to ensure that the DropDownList pulls from this particular table?  Is there a new/different approach that must be taken?

Thanks much for your help and guidance.

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 05 Feb 2015, 01:23 PM
Hello Sid,

In general, context defining is not related to Kendo UI widget. What I would suggest you is to remove the DropDownList list from the page and just output the raw version of the data you would like to display. If the rendered data is the correct JSON, then there should be no reason why it shouldn't work with the dropdownlist.

Regards,
Georgi Krustev
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
Sid
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or