I am having a jquery datatable in which i want the data from query. i am not able to do so
How to Executing Raw Sql Query in MVC
public ActionResult LoadData()
{
using (var Ms = new DHIFeedbackEntities2())
{
var feedbacklist=Ms.FeedBacks.SqlQuery("select [FeedbackUserName],[FeedBackUserEmailID],[FeedBackComment],[Designation],[Organization],[ContactNo],[City],[FeedBackDate] from [DHIFeedback].[dbo].[FeedBack]").ToList<FeedBack>();
return Json(new { data = feedbacklist }, JsonRequestBehavior.AllowGet);
}
}
$(document).ready(function () {
$(document).on("click", ".opencomment", function () {
var mycomment = $(this).data('id');
$('.modal-body #commentdesc').html(mycomment);
// $('#myModal').modal('show');
});
$('#FeedbackDetails').DataTable({
"processing": true,
"ajax": {
"url": "/ViewFeedback/LoadData",
"type": "GET",
"datatype": "json"
},
"lengthMenu": [
[5, 10, 25, 50, 100, -1],
[5, 10, 25, 50, 100, "All"]
],
"autoWidth": true,
"responsive": true,
"lengthChange": true,
"ordering": true,
"fnRowCallback" : function(nRow, aData, iDisplayIndex){
var oSettings = this.fnSettings();
$("td:first", nRow).html(oSettings._iDisplayStart+iDisplayIndex +1);
return nRow;
},
"columns": [
{ "data": null, "autoWidth": true },
{ "data": "FeedbackUserName", "name": "User Name", "autoWidth": true },
{ "data": "FeedBackUserEmailID", "name": "Email ID", "autoWidth": true },
{ "data": "FeedBackComment", "name": "Comment", "autoWidth": true },
{ "data": "Designation", "name": "Designation", "autoWidth": true },
{ "data": "Organization", "name": "Organization", "autoWidth": true },
{ "data": "ContactNo", "name": "Contact No", "autoWidth": true },
{ "data": "City", "name": "City", "autoWidth": true },
{
"data": "DT", "autoWidth": true
},
],
columnDefs: [{
targets: 3,
//data:"FeedbackID",
render: function (data, type, row, meta) {
if (type === 'display' && data.length > 40) {
return '<span title="' + data + '">' + data.substr(0, 38) + '...<a href="" data-id="'+data+'" data-toggle="modal" class="opencomment" data-target="#myModal">Show More</a>';
}
else {
return data;
}
}
}],
"language": {
"emptyTable": "No Events Found Related To This User"
},
});
});
public partial class FeedBack
{
public int FeedbackID { get; set; }
public string FeedbackUserName { get; set; }
public string FeedBackUserEmailID { get; set; }
public string FeedBackComment { get; set; }
public string Designation { get; set; }
public string Organization { get; set; }
public string ContactNo { get; set; }
public string City { get; set; }
public Nullable<System.DateTime> FeedBackDate { get; set; }
public Nullable<double> IsPublished { get; set; }
public string Reply { get; set; }
public Nullable<double> IsReplied { get; set; }
public Nullable<System.DateTime> ReplyDate { get; set; }
public string ReplyBy { get; set; }
public string Sector { get; set; }
public Nullable<int> Status { get; set; }
public string DT { get; set; }
}