Answered by:
DATATABLE FOR INDEX VIEW , ASP.NET MVC5 APP

Question
-
User-1473047469 posted
HI.this is the view and the controller :how can anyone help me show the results into datatableE :
@model IEnumerable<Northwind.Order> @{ ViewBag.Title = ""; Layout = "~/Views/Shared/MasterDetailsLayoutPage.cshtml"; } <p> @Html.ActionLink("Create New", "Create") </p> <table class="table"> <tr> <th> @Html.DisplayNameFor(model => model.CustomerID) </th> <th> @Html.DisplayNameFor(model => model.EmployeeID) </th> <th> @Html.DisplayNameFor(model => model.OrderDate) </th> <th> @Html.DisplayNameFor(model => model.RequiredDate) </th> <th> @Html.DisplayNameFor(model => model.ShippedDate) </th> <th> @Html.DisplayNameFor(model => model.Freight) </th> <th> @Html.DisplayNameFor(model => model.ShipName) </th> <th> @Html.DisplayNameFor(model => model.ShipCountry) </th> <th> @Html.DisplayNameFor(model => model.Customer.CompanyName) </th> <th> @Html.DisplayNameFor(model => model.Employee.LastName) </th> <th> @Html.DisplayNameFor(model => model.Shipper.CompanyName) </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.ActionLink(item.CustomerID, "Details", new { id = item.OrderID }) </td> <td> @Html.DisplayFor(modelItem => item.EmployeeID) </td> <td> @Html.DisplayFor(modelItem => item.OrderDate) </td> <td> @Html.DisplayFor(modelItem => item.RequiredDate) </td> <td> @Html.DisplayFor(modelItem => item.ShippedDate) </td> <td> @Html.DisplayFor(modelItem => item.Freight) </td> <td> @Html.DisplayFor(modelItem => item.ShipName) </td> <td> @Html.DisplayFor(modelItem => item.ShipCountry) </td> <td> @Html.DisplayFor(modelItem => item.Customer.CompanyName) </td> <td> @Html.DisplayFor(modelItem => item.Employee.LastName) </td> <td> @Html.DisplayFor(modelItem => item.Shipper.CompanyName) </td> <td> @Html.ActionLink("Edit", "Edit", new { id=item.OrderID }) | @Html.ActionLink("Details", "Details", new { id=item.OrderID }) | @Html.ActionLink("Delete", "Delete", new { id=item.OrderID }) </td> </tr> } </table> 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 Northwind; namespace Northwind.Controllers { public class OrdersController : Controller { private dbNorthwindEntities db = new dbNorthwindEntities(); // GET: Orders public ActionResult Index() { var orders = db.Orders.Include(o => o.Customer).Include(o => o.Employee).Include(o => o.Shipper); return View(orders.ToList()); } // GET: Orders/Details/5 public ActionResult Details(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Order order = db.Orders.Find(id); if (order == null) { return HttpNotFound(); } return View(order); } // GET: Orders/Create public 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 // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "OrderID,CustomerID,EmployeeID,OrderDate,RequiredDate,ShippedDate,ShipVia,Freight,ShipName,ShipAddress,ShipCity,ShipRegion,ShipPostalCode,ShipCountry")] Order order) { if (ModelState.IsValid) { db.Orders.Add(order); db.SaveChanges(); return RedirectToAction("Details" , new { id = order.OrderID }); } 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/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Order order = db.Orders.Find(id); if (order == null) { return HttpNotFound(); } 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 // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include = "OrderID,CustomerID,EmployeeID,OrderDate,RequiredDate,ShippedDate,ShipVia,Freight,ShipName,ShipAddress,ShipCity,ShipRegion,ShipPostalCode,ShipCountry")] 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/5 public ActionResult Delete(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Order order = db.Orders.Find(id); if (order == null) { return HttpNotFound(); } return View(order); } // POST: Orders/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] 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) { if (disposing) { db.Dispose(); } base.Dispose(disposing); } } }
Monday, January 15, 2018 9:21 AM
Answers
-
User-832373396 posted
<g class="gr_ gr_8 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="8" data-gr-id="8">Hi</g> <g class="gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" id="5" data-gr-id="5">mileycyrus</g>,
help me show the results into datatableE :Sir, I guess that you want to use datatables.js based on the current code in MVC.
If so, please refer to this way:
$(document).ready(function() { $('table').DataTable(); } );
Guide:
https://datatables.net/examples/basic_init/zero_configuration.html
With regards, Angelina Jolie
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, January 17, 2018 6:53 AM
All replies
-
User-832373396 posted
<g class="gr_ gr_8 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="8" data-gr-id="8">Hi</g> <g class="gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" id="5" data-gr-id="5">mileycyrus</g>,
help me show the results into datatableE :Sir, I guess that you want to use datatables.js based on the current code in MVC.
If so, please refer to this way:
$(document).ready(function() { $('table').DataTable(); } );
Guide:
https://datatables.net/examples/basic_init/zero_configuration.html
With regards, Angelina Jolie
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, January 17, 2018 6:53 AM -
User-1473047469 posted
a 10 star answer
Wednesday, January 17, 2018 8:15 AM -
User-1473047469 posted
th nx
Thursday, January 18, 2018 10:21 AM