New to Kendo UI as well as MVC/Entity Framework, so please pardon me if this is a silly question.
I've spent the last 3 days trying to populate a DropDownList from a table within a SQL database. Doing a basic BindTo(Model), I was getting a JSON circular reference error. I eventually found the AJAX binding help page (http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/dropdownlist/overview#configure-the-kendo-dropdownlist-for-ajax-binding) and tried giving that a shot.
I modified it a bit to create a new Json result to contain only the table colums I need and eliminate the circular reference. My application now builds and runs through, but I either get an empty dropdownlist or a spinning/loading image within the dropdownlist. I put a break in the code, and I can see the 'results' array contains the correct information from the database table. What am I doing wrong?
Controller:
namespace KendoUIMvcApplication1.Controllers
{
public class HomeController : Controller
{
pinnwebEntities2 _db = new pinnwebEntities2();
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
public JsonResult GetOUs()
{
var results = Json(from obj in _db.OUs select new { OU1 = obj.OU1, OU_description = obj.OU_description });
return Json(results, JsonRequestBehavior.AllowGet);
}
Index.cshtml:
@{
ViewBag.Title = "Home Page";
}
@(Html.Kendo().DropDownList()
.Name("clients")
.DataTextField("OU_description")
.DataValueField("OU1")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetOUs", "Home"); //Set the Action and Controller name
});
})
.SelectedIndex(0)
)
I've spent the last 3 days trying to populate a DropDownList from a table within a SQL database. Doing a basic BindTo(Model), I was getting a JSON circular reference error. I eventually found the AJAX binding help page (http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/dropdownlist/overview#configure-the-kendo-dropdownlist-for-ajax-binding) and tried giving that a shot.
I modified it a bit to create a new Json result to contain only the table colums I need and eliminate the circular reference. My application now builds and runs through, but I either get an empty dropdownlist or a spinning/loading image within the dropdownlist. I put a break in the code, and I can see the 'results' array contains the correct information from the database table. What am I doing wrong?
Controller:
namespace KendoUIMvcApplication1.Controllers
{
public class HomeController : Controller
{
pinnwebEntities2 _db = new pinnwebEntities2();
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
public JsonResult GetOUs()
{
var results = Json(from obj in _db.OUs select new { OU1 = obj.OU1, OU_description = obj.OU_description });
return Json(results, JsonRequestBehavior.AllowGet);
}
Index.cshtml:
@{
ViewBag.Title = "Home Page";
}
@(Html.Kendo().DropDownList()
.Name("clients")
.DataTextField("OU_description")
.DataValueField("OU1")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetOUs", "Home"); //Set the Action and Controller name
});
})
.SelectedIndex(0)
)