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

Syed Babar AliSyed Babar Ali Posts: 9Questions: 4Answers: 0

======================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

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    "...to load another" is not clear. Please explain your question fully.

  • Syed Babar AliSyed Babar Ali Posts: 9Questions: 4Answers: 0

    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 ?

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin

    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

  • Syed Babar AliSyed Babar Ali Posts: 9Questions: 4Answers: 0

    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

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin

    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

This discussion has been closed.