If you haven't already installed ASP.NET MVC 3 use this resource: http://www.asp.net/mvc/mvc3
For this tutorial you're also going to need the Entity Framework: http://www.microsoft.com/download/en/details.aspx?id=18504
For our purpose we will use the Northwind database which you can download from here. So let's begin!
Create new ASP.NET MVC 3 project and choose the "Empty project" option for template. For "View engine" select "Razor".
using System;using System.Collections.Generic;using System.Data;using System.Data.Entity;using System.Linq;using System.Web;using System.Web.Mvc;using Project.Models;namespace Project.Controllers{public class OrdersController : Controller{private NORTHWNDEntities2 db = new NORTHWNDEntities2();//// GET: /Orders/public ViewResult Index(){var orders = db.Orders.Include(o => o.Customer).Include(o => o.Employee).Include(o => o.Shipper);return View(orders.ToList());}public JsonResult GetOrders(int pagesize, int pagenum){var query = Request.QueryString;var dbResult = db.Database.SqlQuery<Order>(this.BuildQuery(query));var orders = from order in dbResultselect new Order{ShippedDate = order.ShippedDate,ShipName = order.ShipName,ShipAddress = order.ShipAddress,ShipCity = order.ShipCity,ShipCountry = order.ShipCountry};var total = dbResult.Count();orders = orders.Skip(pagesize * pagenum).Take(pagesize);var result = new{TotalRows = total,Rows = orders};return Json(result, JsonRequestBehavior.AllowGet);}//// GET: /Orders/Details/5public ViewResult Details(int id){Order order = db.Orders.Find(id);return View(order);}//// GET: /Orders/Createpublic ActionResult Create(){ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CompanyName");ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "LastName");ViewBag.ShipVia = new SelectList(db.Shippers, "ShipperID", "CompanyName");return View();}//// POST: /Orders/Create[HttpPost]public ActionResult Create(Order order){if (ModelState.IsValid){db.Orders.Add(order);db.SaveChanges();return RedirectToAction("Index");}ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CompanyName", order.CustomerID);ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "LastName", order.EmployeeID);ViewBag.ShipVia = new SelectList(db.Shippers, "ShipperID", "CompanyName", order.ShipVia);return View(order);}//// GET: /Orders/Edit/5public ActionResult Edit(int id){Order order = db.Orders.Find(id);ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CompanyName", order.CustomerID);ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "LastName", order.EmployeeID);ViewBag.ShipVia = new SelectList(db.Shippers, "ShipperID", "CompanyName", order.ShipVia);return View(order);}//// POST: /Orders/Edit/5[HttpPost]public ActionResult Edit(Order order){if (ModelState.IsValid){db.Entry(order).State = EntityState.Modified;db.SaveChanges();return RedirectToAction("Index");}ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CompanyName", order.CustomerID);ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "LastName", order.EmployeeID);ViewBag.ShipVia = new SelectList(db.Shippers, "ShipperID", "CompanyName", order.ShipVia);return View(order);}//// GET: /Orders/Delete/5public ActionResult Delete(int id){Order order = db.Orders.Find(id);return View(order);}//// POST: /Orders/Delete/5[HttpPost, ActionName("Delete")]public ActionResult DeleteConfirmed(int id){Order order = db.Orders.Find(id);db.Orders.Remove(order);db.SaveChanges();return RedirectToAction("Index");}protected override void Dispose(bool disposing){db.Dispose();base.Dispose(disposing);}}}
<script type="text/javascript">$(document).ready(function () {// prepare the datavar source = {datatype: "json",datafields: [{ name: 'ShippedDate', type: 'date' },{ name: 'ShipName' },{ name: 'ShipAddress' },{ name: 'ShipCity' },{ name: 'ShipCountry' }],url: 'Orders/GetOrders',root: 'Rows',beforeprocessing: function (data) {source.totalrecords = data.TotalRows;}};var dataadapter = new $.jqx.dataAdapter(source, {loadError: function (xhr, status, error) {alert(error);}});// initialize jqxGrid$("#jqxgrid").jqxGrid({source: dataadapter,autoheight: true,pageable: true,virtualmode: true,rendergridrows: function (obj) {return obj.data;},columns: [{ text: 'Shipped Date', datafield: 'ShippedDate', cellsformat: 'yyyy-MM-dd', width: 200 },{ text: 'Ship Name', datafield: 'ShipName', width: 200 },{ text: 'Address', datafield: 'ShipAddress', width: 180 },{ text: 'City', datafield: 'ShipCity', width: 100 },{ text: 'Country', datafield: 'ShipCountry', width: 140 }]});});</script><h2>Index</h2><div id="jqxgrid"></div>
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Web.Routing;namespace Project{// Note: For instructions on enabling IIS6 or IIS7 classic mode,// visit http://go.microsoft.com/?LinkId=9394801public class MvcApplication : System.Web.HttpApplication{public static void RegisterGlobalFilters(GlobalFilterCollection filters){filters.Add(new HandleErrorAttribute());}public static void RegisterRoutes(RouteCollection routes){routes.IgnoreRoute("{resource}.axd/{*pathInfo}");routes.MapRoute("Orders", // Route name"{controller}/{action}/{id}", // URL with parametersnew { controller = "Orders", action = "Index", id = UrlParameter.Optional } // Parameter defaults);}protected void Application_Start(){AreaRegistration.RegisterAllAreas();RegisterGlobalFilters(GlobalFilters.Filters);RegisterRoutes(RouteTable.Routes);}}}