MVC Application
Jquery datatable work fine in MVC Application but after publish and host on IIS then Jquery datatable not working.
My View Binding Code :
- @* Load datatable css @ @*<link href="//cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" rel="stylesheet" />*@ <link href="~/Content/DataTable/jquery.dataTables.min.css" rel="stylesheet" /> @ Load datatable js *@ @section Scripts{
- @*<script src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>*@
- <script src="~/Scripts/DataTable/jquery.dataTables.min.js"></script>
- <script>
- $(document).ready(function () {
-
- $('#myTable').DataTable({
- "processing": true,
- "serverSide": true,
- "orderMulti": false,
-
- "filter": true,
-
- "ajax": {
- "url": "/CountryMaster/LoadData",
- "type": "POST",
- "datatype": "json"
- },
- "columns": [
- { "data": "CountryName", "name": "CountryName", "autoWidth": true },
- {
- "data": "CountryId", "width": "50px", "render": function (data) {
- return '<a class="popup" href="/CountryMaster/Edit/' + data + '">Edit</a>';
- }
- }
- ]
- });
- });
- </script>
- }
Controller Code
- [HttpPost]
- public ActionResult LoadData()
- {
-
-
- string Search = Request.Form.GetValues("search[value]")[0];
- var draw = Request.Form.GetValues("draw").FirstOrDefault();
- var start = Request.Form.GetValues("start").FirstOrDefault();
- var length = Request.Form.GetValues("length").FirstOrDefault();
-
- var sortColumn = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
- var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
-
- int pageSize = length != null ? Convert.ToInt32(length) : 0;
- int skip = start != null ? Convert.ToInt32(start) : 0;
- int totalRecords = 0;
- using (CountryEntities dc = new CountryEntities())
- {
- dc.Configuration.LazyLoadingEnabled = false;
-
- var ad = (from dm in db.tblCountry
- select new
- {
- dm.CountryName,
- dm.CountryID,
- }).ToList();
-
- var v = (from a in dc.tblCountry orderby a.countryID select a).AsQueryable();
-
- if (!string.IsNullOrEmpty(Search))
- {
- v = v.Where(a => a.CountryName.Contains(Search.ToLower()));
- }
-
- if (sortColumn!="")
- {
- if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
- {
- v = v.OrderBy(sortColumn + " " + sortColumnDir);
- }
- }
- totalRecords = v.Count();
- var data = v.Skip(skip).Take(pageSize).ToList();
- return Json(new { draw = draw, recordsFiltered = totalRecords, recordsTotal = totalRecords, data = data }, JsonRequestBehavior.AllowGet);
- }
- }