I have a simple controller which sends colored and Name. I want to bind to a kendoUI combobox. I am putting my sample code with this.
Controller
namespace KendoMVCStudy.Controllers
{
public class GetColorController : Controller
{
//
// GET: /GetColor/
public ActionResult Index()
{
Color _color = new Color();
List<Color> _colors = new List<Color>();
_color.Colorid = 1;
_color.Name = "White";
_colors.Add(_color);
_color.Colorid = 2;
_color.Name = "Black";
_colors.Add(_color);
return Json(_colors, JsonRequestBehavior.AllowGet);
//return View(_colors);
}
}
}
Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace KendoMVCStudy.Models
{
public class Color
{
public int Colorid { get; set; }
public string Name { get; set; }
}
}
View
@model List<KendoMVCStudy.Models.Color>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<div class="demo-section">
<h2>Products</h2>
@(Html.Kendo().ComboBox()
.Name("products")
.DataTextField("Name")
.DataValueField("Colorid")
.HtmlAttributes(new { style = "width:250px" })
.Filter("contains")
.AutoBind(true)
.MinLength(3)
.DataSource(source => {
source.Read(read =>
{
read.Action("Index", "GetColor");
})
.ServerFiltering(true);
})
)
</div>
Controller
namespace KendoMVCStudy.Controllers
{
public class GetColorController : Controller
{
//
// GET: /GetColor/
public ActionResult Index()
{
Color _color = new Color();
List<Color> _colors = new List<Color>();
_color.Colorid = 1;
_color.Name = "White";
_colors.Add(_color);
_color.Colorid = 2;
_color.Name = "Black";
_colors.Add(_color);
return Json(_colors, JsonRequestBehavior.AllowGet);
//return View(_colors);
}
}
}
Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace KendoMVCStudy.Models
{
public class Color
{
public int Colorid { get; set; }
public string Name { get; set; }
}
}
View
@model List<KendoMVCStudy.Models.Color>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<div class="demo-section">
<h2>Products</h2>
@(Html.Kendo().ComboBox()
.Name("products")
.DataTextField("Name")
.DataValueField("Colorid")
.HtmlAttributes(new { style = "width:250px" })
.Filter("contains")
.AutoBind(true)
.MinLength(3)
.DataSource(source => {
source.Read(read =>
{
read.Action("Index", "GetColor");
})
.ServerFiltering(true);
})
)
</div>