Hello, I'm new with MVC & Kendo and follow some demo videos (http://www.youtube.com/watch?v=1CPediqnIt8) and tried "do-it yourself".
The Controller:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace KendoUIMvcApplication3.Controllers
{
public class FoldersController : Controller
{
private FotosACSEntities db = new FotosACSEntities();
//
// GET: /Folders/
public ActionResult Index()
{
var folders = db.Folders.Select(f => new
{
ID = f.ID,
Nome = f.Nome
});
return Json(folders, "text/html", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet);
...
The View:
@model IEnumerable<KendoUIMvcApplication3.Folders>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<br />
@Html.Kendo().DropDownList().Name("cbFolders").DataSource(dataSource => dataSource.Read(read => read
.Action("Index", "Folders"))).DataTextField("Nome").DataValueField("ID");
...
And the Result: (IE and Chrome)
[{"ID":1,"Nome":"\\CD 06_Fotos Pessoais"},{"ID":2,"Nome":"\\Fotos Pessoais\\Album 002\\JPG"},{"ID":3,"Nome":"\\Fotos Pessoais\\Album 003\\JPG"},{"ID":4,"Nome":"\\Fotos Pessoais\\Album 004\\JPG"},{"ID":5,"Nome":"\\Fotos Pessoais\\Album 007\\JPG"},{"ID":6,"Nome":"\\Fotos Pessoais\\Album 008\\JPG"},{"ID":7,"Nome":"\\Fotos Pessoais\\Album 009\\JPG"},{"ID":8,"Nome":"\\Fotos Pessoais\\Album 010\\JPG"},{"ID":9,"Nome":"\\Fotos Pessoais\\Album 011\\JPG"},{"ID":10,"Nome":"\\Fotos Pessoais\\Album 013\\JPG"},{"ID":11,"Nome":"\\Fotos Pessoais\\Album 014\\JPG"},{"ID":12,"Nome":"\\Fotos Pessoais\\Album 017\\JPG"},{"ID":13,"Nome":"\\Fotos PM\\Album 001"},{"ID":14,"Nome":"\\Fotos PM\\Album 002"},...
What's happening?
Regards,
Rui
The Controller:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace KendoUIMvcApplication3.Controllers
{
public class FoldersController : Controller
{
private FotosACSEntities db = new FotosACSEntities();
//
// GET: /Folders/
public ActionResult Index()
{
var folders = db.Folders.Select(f => new
{
ID = f.ID,
Nome = f.Nome
});
return Json(folders, "text/html", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet);
...
The View:
@model IEnumerable<KendoUIMvcApplication3.Folders>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<br />
@Html.Kendo().DropDownList().Name("cbFolders").DataSource(dataSource => dataSource.Read(read => read
.Action("Index", "Folders"))).DataTextField("Nome").DataValueField("ID");
...
And the Result: (IE and Chrome)
[{"ID":1,"Nome":"\\CD 06_Fotos Pessoais"},{"ID":2,"Nome":"\\Fotos Pessoais\\Album 002\\JPG"},{"ID":3,"Nome":"\\Fotos Pessoais\\Album 003\\JPG"},{"ID":4,"Nome":"\\Fotos Pessoais\\Album 004\\JPG"},{"ID":5,"Nome":"\\Fotos Pessoais\\Album 007\\JPG"},{"ID":6,"Nome":"\\Fotos Pessoais\\Album 008\\JPG"},{"ID":7,"Nome":"\\Fotos Pessoais\\Album 009\\JPG"},{"ID":8,"Nome":"\\Fotos Pessoais\\Album 010\\JPG"},{"ID":9,"Nome":"\\Fotos Pessoais\\Album 011\\JPG"},{"ID":10,"Nome":"\\Fotos Pessoais\\Album 013\\JPG"},{"ID":11,"Nome":"\\Fotos Pessoais\\Album 014\\JPG"},{"ID":12,"Nome":"\\Fotos Pessoais\\Album 017\\JPG"},{"ID":13,"Nome":"\\Fotos PM\\Album 001"},{"ID":14,"Nome":"\\Fotos PM\\Album 002"},...
What's happening?
Regards,
Rui