I am new in datatable (.NET MVC) How to pass parameter in controller from javascript to load another
I am new in datatable (.NET MVC) How to pass parameter in controller from javascript to load another
======================MVC Controller Method================================
[Route("api/CutomerTable")]
[HttpGet]
[HttpPost]
public IHttpActionResult CutomerTable()
{
var request = HttpContext.Current.Request;
var settings = Properties.Settings.Default;
using (var db = new Database(settings.DbType, settings.DbConnection))
{
var response = new Editor(db, "CutomerTable", "id")
.Model<CutomerTableModel>()
.Process(request)
.Data();
return Json(response);
}
}
=======================Javascript Method===================================
var editor = new $.fn.dataTable.Editor( {
ajax: '/api/CutomerTable',
table: '#CutomerTable',
fields: [
{
"label": "Name:",
"name": "name"
}
]
} );
var table = $('#CutomerTable').DataTable( {
dom: 'Bfrtip',
ajax: '/api/CutomerTable',
columns: [
{
"data": "name"
}
],
select: true,
lengthChange: false,
buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
]
} );
Answers
"...to load another" is not clear. Please explain your question fully.
Basically i have two datatables i want parent child relation to each other and full editable mode.
i am bit confuse how to pass parameter in c# method ?
Are you following this blog post and you aren't sure how to access the ID that is sent in the GET request for the data in the second table, or have I misunderstood?
Allan
Hi Allan!
Yes i follow this blog post but i don't understand how to pass parameter and get parameter in C# MVC Controller method.
Kindly give me syntax.
Thanks
Request.QueryString
is one way to get query string parameters in .NET. You are of course best referring to the MSDN documentation for help with .NET stuff.The blog post shows, on line 8 of the child Editor demo code, how you can pass data to the server using the
ajax.data
option.Allan