Hello I am new to MVC and Syncfusion, The grid doesnt seem retrieve data fro the controller I am using EJS2 with MVC 5.
This cotroller i generated from ADO.NET model throught EF
namespace Plastogram_System.Controllers
{
public class ProductsController : Controller
{
public PlastogramSystemDBEntitiesALL99 db = new PlastogramSystemDBEntitiesALL99();
// GET: Products
public ActionResult Index()
{
var datasource = db.Products.Include(p => p.Location).Include(p => p.Product_Location).Include(p => p.Product_Quote).Include(p => p.Product_Type).Include(p => p.Product_Price);
ViewBag.DataSource = datasource.ToList();
return View(ViewBag.DataSource);
}
// GET: Products/Create
public ActionResult Create()
{
ViewBag.LocationID = new SelectList(db.Locations, "LocationID", "LocationDescription");
ViewBag.ProductID = new SelectList(db.Product_Location, "ProductID", "ProductID");
ViewBag.ProductID = new SelectList(db.Product_Quote, "ProductID", "ProductID");
ViewBag.ProductTypeID = new SelectList(db.Product_Type, "ProductTypeID", "ProductTypeDescription");
ViewBag.PriceID = new SelectList(db.Product_Price, "PriceID", "PriceID");
return View();
}
// POST: Products/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.
[System.Web.Http.HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ProductID,ProductName,ProductColour,ProductTypeID,ProductQuantity,ProductBarcode,ProductPrice,Unitsize,ProductSize,LocationID,PriceID")] Product product)
{
if (ModelState.IsValid)
{
db.Products.Add(product);
db.SaveChanges();
return RedirectToAction("Create");
}
ViewBag.LocationID = new SelectList(db.Locations, "LocationID", "LocationDescription", product.LocationID);
ViewBag.ProductID = new SelectList(db.Product_Location, "ProductID", "ProductID", product.ProductID);
ViewBag.ProductID = new SelectList(db.Product_Quote, "ProductID", "ProductID", product.ProductID);
ViewBag.ProductTypeID = new SelectList(db.Product_Type, "ProductTypeID", "ProductTypeDescription", product.ProductTypeID);
ViewBag.PriceID = new SelectList(db.Product_Price, "PriceID", "PriceID", product.PriceID);
return View(product);
}
// GET: Products/Delete/5
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Product product = db.Products.Find(id);
if (product == null)
{
return HttpNotFound();
}
return View(product);
}
// POST: Products/Delete/5
[System.Web.Http.HttpPost, System.Web.Http.ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
Product product = db.Products.Find(id);
db.Products.Remove(product);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
This my view
@model IEnumerable<Plastogram_System.Models.Product>
@Html.EJS().Grid("CommandColumn").DataSource(dataManager => { dataManager.Url("/Products/Index").Adaptor("UrlAdaptor"); }).Columns(col =>
{
col.Field("ProductID").HeaderText("ProductID").IsPrimaryKey(true).Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("ProductName").HeaderText("ProductName").Width("150").Add();
col.Field("ProductQuantity").HeaderText("ProductQuantity").Width("120").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("LocationDescription").HeaderText("LocationDescription").EditType("dropdownedit").Width("150").Add();
}).AllowPaging().AllowSorting().AllowFiltering().Toolbar(new List<string>() { "Search" }).Render()
I have tried lot of the binding options at https://ej2.syncfusion.com/aspnetmvc/documentation/grid/databinding.html
and these is the one that displays the table loading but it doesnt show data inside it. Please help i had the same problem with Kendo as well.