Datatables.net 2 Tabbed Table Ajax Get ASP.NET - asp.net

I have a single Datatable configured using Datatables.net where I'm using bootstrap tabs to load a different dataset when a different tab is selected.
Ive configured it by referencing these two examples:
http://live.datatables.net/sozobucu/41/edit and http://www.tutorialrepublic.com/codelab.php?topic=bootstrap&file=create-dynamic-tabs-via-data-attribute.
When I run the application, I see that both Ajax Posts are submitted simultaneously and that the MVC controller switches back and forth line by line between the two ActionResults PopulateObjectATables and PopulateObjectBTables when I debug. I also notice that the JSON the app prepares to return looks correct at the time of the method return.
The issue is that the tab for ObjectA loads correctly and the JSON is returned from the server. However, I receive an error for ObjectB that refers me to http://datatables.net/tn/7 and in firebug I see that HTML is returned instead of JSON and a 502.3 Bad Gateway error is received.
As I see the correct JSON being prepared and both MVC ActionResults are written the same Ive ran out of things that I know to look for.
Scripts
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="~/lib/respond/dest/respond.min.js"></script>
<script src="~/lib/datatables/media/js/jquery.dataTables.js"></script>
<script src="http://cdn.datatables.net/responsive/1.0.6/js/dataTables.responsive.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.7/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.9/css/dataTables.bootstrap.min.css" />
<link href="//cdn.datatables.net/responsive/1.0.6/css/dataTables.responsive.css" rel="stylesheet" />
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
#*<link rel="stylesheet" href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css"/>*#
<link rel="stylesheet" href="~/css/site.css"/>
#*<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.min.js"></script>*#
<script src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js"></script>
<script src="~/lib/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js"></script>
<script src="~/lib/angular/angular.js"></script>
<script src="~/lib/angular-datatables/dist/angular-datatables.js"></script>
View
#model NewInventory.ViewModels.ExampleAllViewModel
<p>
#Html.ActionLink("Create New", "Create")
</p>
<div class="container">
<div class="row">
<div class="well well-lg">
<ul class="nav nav-tabs">
<li class="active objectA-tab"><a data-toggle="tab" role="tab" data-target="#ObjectAData">Object A</a></li>
<li class="objectB-tab"><a data-toggle="tab" role="tab" data-target="#ObjectBData">Object B</a></li>
</ul>
<div class="tab-content">
<div id="ObjectAData" class="tab-pane fade in active" role="tabpanel">
<table id="ObjectATable1" class="table dt-responsive" cellspacing="0" style="width:100%">
<thead>
<tr>
<th>Example1</th>
<th>Example2</th>
<th>Example3</th>
<th>Example4</th>
<th>Example5</th>
<th>Example6</th>
<th>Example7</th>
<th>Example8</th>
<th>Example9</th>
</tr>
</thead>
</table>
</div>
<div id="ObjectBData" class="tab-pane fade in" role="tabpanel">
<table id="ObjectBTable1" class="table dt-responsive" cellspacing="0" style="width:100%">
<thead>
<tr>
<th>Example1</th>
<th>Example2</th>
<th>Example3</th>
<th>Example4</th>
<th>Example5</th>
<th>Example6</th>
<th>Example7</th>
<th>Example12</th>
<th>Example13</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function () {
$('[data-toggle="popover"]').popover();
});
</script>
<script>
$('body').on('click', function (e) {
$('[data-toggle="popover"]').each(function () {
//the 'is' for buttons that trigger popups
//the 'has' for icons within a button that triggers a popup
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
$(this).popover('hide');
}
});
});
</script>
<script>
$(document).ready(function () {
$("a[data-toggle=\"tab\"]").on("shown.bs.tab", function (e) {
console.log('show tab');
$($.fn.dataTable.tables(true)).DataTable()
.columns.adjust()
.responsive.recalc();
});
$("#ObjectATable1").dataTable({
"bServerSide": true,
"sAjaxSource": "PopulateObjectATables",
"bProcessing": true,
"ordering": false,
"paging": false,
"scrollY": "150px",
"searching": false,
"info": false,
"columns": [
{ "data": "Example1" },
{ "data": "Example2" },
{ "data": "Example3" },
{ "data": "Example4" },
{ "data": "Example5" },
{ "data": "Example6" },
{ "data": "Example7" },
{ "data": "Example8" },
{ "data": "Example9" }]
//"deferRender": true,
});
$("#ObjectBTable1").dataTable({
"bServerSide": true,
"sAjaxSource": "PopulateObjectBTables",
"bProcessing": true,
"ordering": false,
"paging": false,
"scrollY": "150px",
"searching": false,
"info": false,
//"deferRender": true,
"columns": [
{ "data": "Example1" },
{ "data": "Example2" },
{ "data": "Example3" },
{ "data": "Example4" },
{ "data": "Example5" },
{ "data": "Example6" },
{ "data": "Example7" },
{ "data": "Example12" },
{ "data": "Example13" }
]
});
});
</script>
MVC Controller ActionResults
public ActionResult PopulateObjectATables(jQueryDataTableParamModel param)
{
ExampleAllViewModel myVM = new ExampleAllViewModel();
List<ObjectA> ObjectAList = new List<ObjectA>(_repository.GetAllObjectA().ToList());
myVM.ListObjectA = ObjectAList;
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = myVM.ListObjectA.Count(),
iTotalDisplayRecords = myVM.ListObjectA.Count(),
aaData = myVM.ListObjectA
});
}
public ActionResult PopulateObjectBTables(jQueryDataTableParamModel param)
{
ExampleAllViewModel myVM = new ExampleAllViewModel();
List<ObjectB> ObjectBList = new List<ObjectB>(_repository.GetAllObjectB().ToList());
myVM.ListObjectB = ObjectBList;
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = myVM.ListObjectB.Count(),
iTotalDisplayRecords = myVM.ListObjectB.Count(),
aaData = myVM.ListObjectB
});
}

Although the errors themselves were not very descriptive or indicative of the root cause I was able to finally get the table ajax calls working once I realized the only difference between my two MVC ActionResult methods.
For ObjectB, inside of my repository method List<ObjectB> ObjectBList = new List<ObjectB>(_repository.GetAllObjectB().ToList()); I was eager loading a related entity along with ObjectB. However for ObjectA I was only returning ObjectA from the database.
Once I removed the include as shown below, the errors resolved.
return _context.ObjectB.ToList();
//return _context.ObjectB.Include(x => x.ObjectC).ToList();

Related

How to pass data from JsonResult in json format to JQGrid? PLease I need help I am stuck in this problem for days. I am reposting this question again

I am trying to pass data from controller to GQ grid. I have done implemented the SQL operation - selecting a row- in another file and returning a object of list type List<Models.ViewModel.Itegration> to the Controller. I implemented the controller of type JsonResult which returns the data in json format. The controller is using [HttpGet] Attritute. I have attached code of my controller, html, js file and screenshot of the issue. The Google Console is not showing any problem. The table is getting ready, but the table data is showing. I guess there is the issue with "passing the data" properly. It would be very helpful for me if anybody could just check my code and let me know where I am getting wrong.
My database consist of single row and two columns, which are: Name and Email. Additionally, I want to add edit button in third row.
Additionally, is there any software, where I can check where the issue is coming while connecting to server, because in this case Google inspect tool is not helpful at all.
In my controller, by using breakpoint I have checked that in Integrations value = db.GetIntegrationRow(); I am getting a correct value in value.
Controller:
#region Namespace
using MCNIDev.DBAccess;
using MCNIDev.Models.ViewModel;
using MCNIDev.Processor.Services;
using System.Web.Mvc;
#endregion
namespace MCNIDev.Content
{
/// <summary>
/// This controller class is responsible for all action in Integration view
/// </summary>
public class IntegrationsController : Controller
{
public ActionResult Details()
{
return PartialView();
}
/// <summary>
/// To get the data for JQGrid
/// </summary>
[HttpGet]
public JsonResult Detail()
{
IntegrationsProcessor db = new IntegrationsProcessor(new MCNIDbContext());
Integrations value = db.GetIntegrationRow();
return new JsonResult()
{
Data = value,
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}
}
}
HTML file
#using MCNIDev.CustomControls
#model MCNIDev.Models.ViewModel.Integrations
#{
ViewBag.Title = "Details";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=devicexb c-width" />
<title>Integrations</title>
</head>
#Styles.Render("~/Content/toasterCss")
#Styles.Render("~/Content/dataPickerCss")
<style type="text/css">
.btn {
min-width: 80px !important;
}
</style>
<body>
#using (Html.BeginForm("", "Integrations", FormMethod.Post, new { enctype = "multipart/form-data", #class = "form-horizontal", id = "frmManifestOrders" }))
{
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0 text-dark">Integrations</h1>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div><!-- /.content-header -->
<section class="content">
<div class="container-fluid">
<div class="card card-block">
<div class="row table-responsive">
<div class="col-md-12">
<div class="row">
<div class="col-md-12 col-sm-12">
<table id="tblSelectIntegrations"></table>
<div id="divSelect"></div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-12">
<hr />
<input type="button" class="btn btn-secondary" onclick="document.location.href='/Dashboard/Dashboard';" value="Cancel" />
</div>
</div>
</div>
</div>
</div>
</div>
</section>
}
</body>
</html>
#*Bundle file includes the path to single JavaScript file Integration that does GQGrid operation *#
#Scripts.Render("~/bundles/integrations")
<script>
$(document).ready(function(){
Integrate.GetValue();
});
</script>
JavaScript file:
var Integrate = function() {
function GetValue() {
$("#tblSelectIntegrations").jqGrid({
mtype: "GET",
url: "/Integrations/Detail",
datatype: "json",
async: false,
colNames: [
"First Name", "Email Address",""
],
colModel: [
//{
// name: '',
// key: false,
// width: 30,
// editable: true,
// formatter: function () {
// return "<input type='checkbox' value='Select' class='fm-button ui-state-default ui-corner-all fm-button-icon-left noPrint'\>";
// }
//},
{ key: false, name: 'IntegrationName', index: 'IntegrationName', editable: false, width: 200 },
{ key: false, name: 'CompanyEmail', index: 'CompanyEmail', editable: false, width: 200 },
{ key: false, name: 'Blank', index: 'Blank', editable: false, width: 200 }
],
pager: jQuery("#divSelect"),
rowNum: 1,
scroll: 0,
height: $(window).innerHeight() - 450,
width: "100%",
viewrecords: true,
caption: "Product",
emptyrecords: "No records to display",
jsonReader: {
root: "",
page: "page",
total: "total",
records: "records",
repeatitems: false
},
autowidth: true,
multiselect: false,
loadonce: false,
ajaxGridOptions: { cache: false },
}).navGrid("tblSelectIntegrations", { edit: false, add: false, del: false, search: false, refresh: false });
}
return {
GetValue: GetValue
};
}();
This is what I am getting-screenshot:

How to parse data from Controller to view using JQGrid?

I am trying to pass data from controller to GQ grid. I have done implemented the SQL operation - selecting a row- in another file and returning a object of list type List<Models.ViewModel.Itegration> to the Controller. I implemented the controller of type JsonResult which returns the data in json format. The controller is using [HttpGet] Attritute. I have attached code of my controller, html, js file and screenshot of the issue. The Google Console is not showing any problem. The table is getting ready, but the table data is showing. I guess there is the issue with "passing the data" properly. It would be very helpful for me if anybody could just check my code and let me know where I am getting wrong.
Additionally, is there any software, where I can check where the issue is coming while connecting to server, because in this case Google inspect tool is not helpful at all.
In my controller, by using breakpoint I have checked that in Integrations value = db.GetIntegrationRow(); I am getting a correct value in value.
Controller:
#region Namespace
using MCNIDev.DBAccess;
using MCNIDev.Models.ViewModel;
using MCNIDev.Processor.Services;
using System.Web.Mvc;
#endregion
namespace MCNIDev.Content
{
/// <summary>
/// This controller class is responsible for all action in Integration view
/// </summary>
public class IntegrationsController : Controller
{
public ActionResult Details()
{
return PartialView();
}
/// <summary>
/// To get the data for JQGrid
/// </summary>
[HttpGet]
public JsonResult Detail()
{
IntegrationsProcessor db = new IntegrationsProcessor(new MCNIDbContext());
Integrations value = db.GetIntegrationRow();
return new JsonResult()
{
Data = value,
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}
}
}
HTML file
#using MCNIDev.CustomControls
#model MCNIDev.Models.ViewModel.Integrations
#{
ViewBag.Title = "Details";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=devicexb c-width" />
<title>Integrations</title>
</head>
#Styles.Render("~/Content/toasterCss")
#Styles.Render("~/Content/dataPickerCss")
<style type="text/css">
.btn {
min-width: 80px !important;
}
</style>
<body>
#using (Html.BeginForm("", "Integrations", FormMethod.Post, new { enctype = "multipart/form-data", #class = "form-horizontal", id = "frmManifestOrders" }))
{
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0 text-dark">Integrations</h1>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div><!-- /.content-header -->
<section class="content">
<div class="container-fluid">
<div class="card card-block">
<div class="row table-responsive">
<div class="col-md-12">
<div class="row">
<div class="col-md-12 col-sm-12">
<table id="tblSelectIntegrations"></table>
<div id="divSelect"></div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-12">
<hr />
<input type="button" class="btn btn-secondary" onclick="document.location.href='/Dashboard/Dashboard';" value="Cancel" />
</div>
</div>
</div>
</div>
</div>
</div>
</section>
}
</body>
</html>
#*Bundle file includes the path to single JavaScript file Integration that does GQGrid operation *#
#Scripts.Render("~/bundles/integrations")
<script>
$(document).ready(function(){
Integrate.GetValue();
});
</script>
JavaScript file:
var Integrate = function() {
function GetValue() {
$("#tblSelectIntegrations").jqGrid({
mtype: "GET",
url: "/Integrations/Detail",
datatype: "json",
async: false,
colNames: [
"First Name", "Email Address",""
],
colModel: [
//{
// name: '',
// key: false,
// width: 30,
// editable: true,
// formatter: function () {
// return "<input type='checkbox' value='Select' class='fm-button ui-state-default ui-corner-all fm-button-icon-left noPrint'\>";
// }
//},
{ key: false, name: 'IntegrationName', index: 'IntegrationName', editable: false, width: 200 },
{ key: false, name: 'CompanyEmail', index: 'CompanyEmail', editable: false, width: 200 },
{ key: false, name: 'Blank', index: 'Blank', editable: false, width: 200 }
],
pager: jQuery("#divSelect"),
rowNum: 1,
scroll: 0,
height: $(window).innerHeight() - 450,
width: "100%",
viewrecords: true,
caption: "Product",
emptyrecords: "No records to display",
jsonReader: {
root: "",
page: "page",
total: "total",
records: "records",
repeatitems: false
},
autowidth: true,
multiselect: false,
loadonce: false,
ajaxGridOptions: { cache: false },
}).navGrid("tblSelectIntegrations", { edit: false, add: false, del: false, search: false, refresh: false });
}
return {
GetValue: GetValue
};
}();
The issue lies in controller. I am trying to send data without telling JQGrid where to insert data.
var jsonData = new
{
rows = value
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
Replace below code with above code
return new JsonResult()
{
Data = value,
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
In my first code I've mentioned that add my data in the rows.
return new JsonResult()
{
Data = value,
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
Replace the above code with the below code.
int totalRecords = value.Count();
var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);
var JsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = value
};
return Json(JsonData, JsonRequestBehavior.AllowGet);

Send Variable from AJAX table to ASP.NET MVC Controller

I understand the topic is relatively common, but I've spent a LONG time trying to solve this issue with pre-existing posts and I have come up with no luck to solving my issue.
I have got a Homepage with a small database of "Safes", When a user clicks on one of the safes, it should take them to the "Items" Database view and show ONLY the items of the safe they clicked on. However, instead it shows no results? (I have got the items table to display ALL results, so I know it is not an issue with the database). More baffling is that the "data" I wish to use as the filter does show properly in the URL, so that should be fine too?
Any help would be MUCH appreciated... Thanks in advance peeps! :)
$(document).ready(function () {
var oTable = $('#CBR').DataTable({
"ajax": {
"url": '/Home/GetSafe',
"type": "get",
"datatype": "json"
},
"columns": [
{ "data": "Safe_ID", "autoWidth": true },
{ "data": "Department_ID", "autoWidth": true },
{
"data": "Safe_ID", "width": "50px", "render": function (selectedSafe) {
$.ajax({
url: '/Home/GetSafeItems',
dataType: "json",
data: { selectedSafe: selectedSafe },
type: "GET",
success: function (data) {
if (data.success) {
alert(data.message);
}
},
error: function (xhr) {
alert(selectedSafe);
}
});
return 'Open Safe';
}
}
]
})
HOMEPAGE VIEW (above)
public ActionResult GetSafeItems(string selectedSafe)
{
using (CBREntities2 dc = new CBREntities2())
{
var safeItem = dc.Items.Where(a => a.Safe_ID == selectedSafe).Select(s => new {
Serial_Number = s.Serial_Number,
Safe_ID = s.Safe_ID,
Date_of_Entry = s.Date_of_Entry,
Title_subject = s.Title_subject,
Document_Type = s.Document_Type,
Sender_of_Originator = s.Sender_of_Originator,
Reference_Number = s.Reference_Number,
Protective_Marking = s.Protective_Marking,
Number_recieved_produced = s.Number_recieved_produced,
copy_number = s.copy_number,
Status = s.Status,
Same_day_Loan = s.Same_day_Loan
}).ToList();
// var safeItems = dc.Items.Where(a => a.Safe_ID).Select(s => new { Safe_ID = s.Safe_ID, Department_ID = s.Department_ID, User_ID = s.User_ID }).ToList();
return Json(new { data = safeItem }, JsonRequestBehavior.AllowGet);
}
}
Controller (above)
#{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Items</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet"
href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" />
<link href="~/Content/themes/base/jquery-ui.min.css" rel="stylesheet" />
</head>
<body>
<div style="width:90%; margin:0 auto" class="tablecontainer">
<a class="popup btn btn-primary" href="/home/SaveItem/0" style="margin-
bottom:20px; margin-top:20px">Add new Item </a>
<table id="CBR-Item">
<thead>
<tr>
<th>Serial Number</th>
<th>Safe ID</th>
<th>Date of Entry</th>
<th>Title/Subject</th>
<th>Document type</th>
<th>Sender of Originator</th>
<th>Reference Number</th>
<th>Protective Marking</th>
<th>Number recieved/produced</th>
<th>Copy number</th>
<th>Status</th>
<th>Same-Day Loan</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
</table>
</div>
<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script src="~/Scripts/jquery-ui-1.12.1.min.js"></script>
<script>
$(document).ready(function () {
var oTable = $('#CBR-Item').DataTable({
"ajax": {
"url": '/Home/GetSafeItems',
"type": "get",
"datatype": "json"
},
"columns": [
{ "data": "Serial_Number", "autoWidth": true },
{ "data": "Safe_ID", "autoWidth": true },
{ "data": "Date_of_Entry", "autoWidth": true },
{ "data": "Title_subject", "autoWidth": true },
{ "data": "Document_Type", "autoWidth": true },
{ "data": "Sender_of_Originator", "autoWidth": true },
{ "data": "Reference_Number", "autoWidth": true },
{ "data": "Protective_Marking", "autoWidth": true },
{ "data": "Number_recieved_produced", "autoWidth": true },
{ "data": "copy_number", "autoWidth": true },
{ "data": "Status", "autoWidth": true },
{ "data": "Same_day_Loan", "autoWidth": true },
{
"data": "Serial_Number", "width": "50px", "render": function (data) {
return '<a class="popup" href="/home/SaveItem/' + data + '">Edit</a>';
}
},
{
"data": "Serial_Number", "width": "50px", "render": function (data) {
return '<a class="popup" href="/home/DeleteItem/' + data + '">Delete</a>';
}
}
]
})
$('.tablecontainer').on('click', 'a.popup', function (e) {
e.preventDefault();
OpenPopup($(this).attr('href'));
})
function OpenPopup(pageUrl) {
var $pageContent = $('<div/>');
$pageContent.load(pageUrl, function () {
$('#popupForm', $pageContent).removeData('validator');
$('#popupForm', $pageContent).removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse('form');
});
$dialog = $('<div class="popupWindow" style="overflow:auto"></div>')
.html($pageContent)
.dialog({
draggable: false,
autoOpen: false,
resizable: false,
model: true,
title: 'Popup Dialog',
height: 550,
width: 600,
close: function () {
$dialog.dialog('destroy').remove();
}
})
$('.popupWindow').on('submit', '#popupForm', function (e) {
var url = $('#popupForm')[0].action;
$.ajax({
type: "POST",
url: url,
data: $('#popupForm').serialize(),
success: function (data) {
if (data.status) {
$dialog.dialog('close');
oTable.ajax.reload();
}
}
})
e.preventDefault();
})
$dialog.dialog('open');
}
})
</script>
Main safe View (above)
I have not inlcuded the safe view as that element works usually without the filter and is calling to the controller method. But can upload if needed.
Amendment: I have almost solved the post issue... but the post won't actually reach the controller (it just keeps tripping the error value in the code Below)
{
"data": "Safe_ID", "width": "50px", "render": function (data) {
return '<a class="safeLink" href="/home/safeItems/' + data + '">Open Safe</a>';
// return { selectedSafe: selectedSafe }
}
}
]
})
$('.tablecontainer').on('click', 'a.safeLink', function (e) {
e.preventDefault();
var whatWhat = "SEC-1000";
var selectedSafeZZ = { theSafe: whatWhat };
$.ajax({
url: '/Home/GetSafeItems',
data: JSON.stringify(selectedSafeZZ),
contentType: "application/json; charset=utf-8;",
type: "POST",
success: function (data) {
alert(data);
},
error: function (xhr) {
alert("Boohooo");
}
});
Your ajax call has nothing to do with anchor tag link. So do you have any method in home controller which returns data to view like viewresult.?
Can you paste your complete controllers code

Need to transform Razor code on ASPX code

So, I need help to make this code work as ASPX, can anyone help me?
I know it,s just a few parts to be changed, but i don't know how to do it...
Or if Any one know hot to achive the same result other way this would be very helpfull.
I already try do it myself but got no luck doing so.. =/
So, I need help to make this code work as ASPX, can anyone help me?
I know it,s just a few parts to be changed, but i don't know how to do it...
Or if Any one know hot to achive the same result other way this would be very helpfull.
I already try do it myself but got no luck doing so.. =/
#{
ViewBag.Title = "Employee List";
}
<a class="btn btn-success" style="margin-bottom:10px"
onclick="PopupForm('#Url.Action("AddOrEdit","Employee")')"><i class="fa fa-
plus"></i> Add New</a>
<table id="employeeTable" class="table table-striped table-bordered"
style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Salary</th>
<th></th>
</tr>
</thead>
</table>
<link href="https://cdn.datatables.net/1.10.15/css/dataTables.bootstrap.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
#section scripts{
<script src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap.min.js"></script>
<script>
var Popup, dataTable;
$(document).ready(function () {
dataTable = $("#employeeTable").DataTable({
"ajax": {
"url": "/Employee/GetData",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "Name" },
{ "data": "Position" },
{ "data": "Office" },
{ "data": "Age" },
{ "data": "Salary" },
{"data":"EmployeeID" , "render" : function (data) {
return "<a class='btn btn-default btn-sm' onclick=PopupForm('#Url.Action("AddOrEdit","Employee")/" + data + "')><i class='fa fa-pencil'></i> Edit</a><a class='btn btn-danger btn-sm' style='margin-left:5px' onclick=Delete("+data+")><i class='fa fa-trash'></i> Delete</a>";
},
"orderable": false,
"searchable":false,
"width":"150px"
}
],
"language": {
"emptyTable" : "No data found, Please click on <b>Add New</b> Button"
}
});
});
function PopupForm(url) {
var formDiv = $('<div/>');
$.get(url)
.done(function (response) {
formDiv.html(response);
Popup = formDiv.dialog({
autoOpen: true,
resizable: false,
title: 'Fill Employee Details',
height: 500,
width: 700,
close: function () {
Popup.dialog('destroy').remove();
}
});
});
}
function SubmitForm(form) {
$.validator.unobtrusive.parse(form);
if($(form).valid()){
$.ajax({
type : "POST",
url : form.action,
data : $(form).serialize(),
success : function (data) {
if(data.success)
{
Popup.dialog('close');
dataTable.ajax.reload();
$.notify(data.message,{
globalPosition :"top center",
className : "success"
})
}
}
});
}
return false;
}
function Delete(id) {
if(confirm('Are You Sure to Delete this Employee Record ?'))
{
$.ajax({
type: "POST",
url: '#Url.Action("Delete","Employee")/' + id,
success: function (data) {
if (data.success)
{
dataTable.ajax.reload();
$.notify(data.message, {
globalPosition: "top center",
className: "success"
})
}
}
});
}
}
</script>
}

emberjs router class active

I know i can find examples of this but i cant put it into my code without errors... just dont know why.
I want start with set class="menu-active" to first in menu.
<li><a {{action gotoAbout}} >About</a></li>
And later when somebody click other position of menu move class="menu-active" to this position.
http://jsfiddle.net/kwladyka/LGArM/3/
And the bonus question: Do you have any remarks to make my code better?
HTML
<script type="text/x-handlebars" data-template-name="application">
{{view App.NavbarView}}
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="navbar">
<div id="menu" class="grid_12">
<ul>
<li><a {{bindAttr class="isAbout:active"}} {{action gotoAbout}} >About</a></li>
<li><a {{bindAttr class="isProjects:active"}} {{action gotoProjects}} >Projekty</a></li>
<li><a {{action gotoTechnology}} >Technologie</a></li>
<li><a {{action gotoContact}} >Kontakt</a></li>
</ul>
</div>
</script>
EMBERJS
$(function() {
console.log("### emberjs start ###");
App = Em.Application.create({
rootElement: '#emberjs-container'
});
App.ApplicationController = Em.Controller.extend();
App.ApplicationView = Em.View.extend({
templateName: 'application'
});
App.NavbarController = Em.Controller.extend({
});
App.NavbarView = Em.View.extend({
templateName: 'navbar',
});
App.AboutView = Em.View.extend({
templateName: 'about'
});
App.ProjectsView = Em.View.extend({
templateName: 'projects'
});
App.TechnologyView = Em.View.extend({
templateName: 'technology'
});
App.ContactView = Em.View.extend({
templateName: 'contact'
});
App.Router = Em.Router.extend({
enableLogging: true,
location: 'hash',
root: Em.Route.extend({
// EVENTS
gotoAbout: Ember.Route.transitionTo('about'),
gotoProjects: Ember.Route.transitionTo('projects'),
gotoTechnology: Ember.Route.transitionTo('technology'),
gotoContact: Ember.Route.transitionTo('contact'),
// STATES
about: Em.Route.extend({
route: '/',
connectOutlets: function (router, context) {
router.get('applicationController').connectOutlet('about');
}
}),
projects: Em.Route.extend({
route: '/projects',
connectOutlets: function (router, context) {
router.get('applicationController').connectOutlet('projects');
}
}),
technology: Em.Route.extend({
route: '/technology',
connectOutlets: function (router, context) {
router.get('applicationController').connectOutlet('technology');
}
}),
contact: Em.Route.extend({
route: '/contact',
connectOutlets: function (router, context) {
router.get('applicationController').connectOutlet('contact');
}
})
})
});
App.initialize();
});

Resources