Nencho,
Thank you for your response. I will explain:
I have setup a working ADO.NET Entity Data Model and as a part of it I am connecting to a table called UPCI_DistrictLookup. Here is the file that was generated by that:
namespace UPCIkuiApps.Models
{
using System;
using System.Collections.Generic;
public partial class UPCI_DistrictLookup
{
public long RecordId { get; set; }
public long District { get; set; }
public string Country { get; set; }
public string State { get; set; }
public string ZipPostal { get; set; }
}
}
I know this entity data model returns results because if I create the scaffolding item using "Add Scaffold", "MVC 5 Controller with views, using Entity Framework" and I select the model class created by the data entity model class called UPCI_DistrictLookup and have it generate the controller and views for me, they work. Here is the working controller:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using UPCIkuiApps.Models;
namespace UPCIkuiApps.Controllers
{
public class UPCI_DistrictLookupWorkingController : Controller
{
private SE_PRODEntities db = new SE_PRODEntities();
// GET: UPCI_DistrictLookupWorking
public ActionResult Index()
{
return View(db.UPCI_DistrictLookup.ToList());
}
// GET: UPCI_DistrictLookupWorking/Details/5
public ActionResult Details(long? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
UPCI_DistrictLookup uPCI_DistrictLookup = db.UPCI_DistrictLookup.Find(id);
if (uPCI_DistrictLookup == null)
{
return HttpNotFound();
}
return View(uPCI_DistrictLookup);
}
// GET: UPCI_DistrictLookupWorking/Create
public ActionResult Create()
{
return View();
}
// POST: UPCI_DistrictLookupWorking/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "RecordId,District,Country,State,ZipPostal")] UPCI_DistrictLookup uPCI_DistrictLookup)
{
if (ModelState.IsValid)
{
db.UPCI_DistrictLookup.Add(uPCI_DistrictLookup);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(uPCI_DistrictLookup);
}
// GET: UPCI_DistrictLookupWorking/Edit/5
public ActionResult Edit(long? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
UPCI_DistrictLookup uPCI_DistrictLookup = db.UPCI_DistrictLookup.Find(id);
if (uPCI_DistrictLookup == null)
{
return HttpNotFound();
}
return View(uPCI_DistrictLookup);
}
// POST: UPCI_DistrictLookupWorking/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "RecordId,District,Country,State,ZipPostal")] UPCI_DistrictLookup uPCI_DistrictLookup)
{
if (ModelState.IsValid)
{
db.Entry(uPCI_DistrictLookup).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(uPCI_DistrictLookup);
}
// GET: UPCI_DistrictLookupWorking/Delete/5
public ActionResult Delete(long? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
UPCI_DistrictLookup uPCI_DistrictLookup = db.UPCI_DistrictLookup.Find(id);
if (uPCI_DistrictLookup == null)
{
return HttpNotFound();
}
return View(uPCI_DistrictLookup);
}
// POST: UPCI_DistrictLookupWorking/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(long id)
{
UPCI_DistrictLookup uPCI_DistrictLookup = db.UPCI_DistrictLookup.Find(id);
db.UPCI_DistrictLookup.Remove(uPCI_DistrictLookup);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
And here is the working view:
@model IEnumerable<UPCIkuiApps.Models.UPCI_DistrictLookup>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Country)
</th>
<th>
@Html.DisplayNameFor(model => model.State)
</th>
<th>
@Html.DisplayNameFor(model => model.ZipPostal)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Country)
</td>
<td>
@Html.DisplayFor(modelItem => item.State)
</td>
<td>
@Html.DisplayFor(modelItem => item.ZipPostal)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</table>
Then, when I do the same thing using the Kendo UI scaffolding. It creates this controller:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using UPCIkuiApps.Models;
namespace UPCIkuiApps.Controllers
{
public class UDistLookupController : Controller
{
private SE_PRODEntities db = new SE_PRODEntities();
public ActionResult Index()
{
return View();
}
public ActionResult UPCI_DistrictLookup_Read([DataSourceRequest]DataSourceRequest request)
{
IQueryable<UPCI_DistrictLookup> upci_districtlookup = db.UPCI_DistrictLookup;
DataSourceResult result = upci_districtlookup.ToDataSourceResult(request, uPCI_DistrictLookup => new {
RecordId = uPCI_DistrictLookup.RecordId,
Country = uPCI_DistrictLookup.Country,
State = uPCI_DistrictLookup.State,
ZipPostal = uPCI_DistrictLookup.ZipPostal
});
return Json(result);
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}
And it creates this view which does return the column headers, but nothing shows in the data.
<div id="grid"></div>
<script>
$("#grid").kendoGrid({
height: 400,
columns: [
{field: "Country"},
{field: "State"},
{field: "ZipPostal"}
],
dataSource: {
type: "aspnetmvc-ajax",
transport: {
read: {
url: "UPCI_DistrictLookup_Read"
}
},
schema: {
data: "Data",
model: {
id: "RecordId",
fields: {
RecordId: { type: "number"},
District: { type: "number"},
Country: { type: "string"},
State: { type: "string"},
ZipPostal: { type: "string"}
}
}
},
serverPaging: true,
serverSorting: true,
serverSorting: true,
},
scrollable: true
})
</script>
Thank you for your help.