using ajax in javascript value view to controller in c#
public ActionResult GetData(int customerID, string fname = "")
{
// Initialization.
JsonResult result = new JsonResult();
DataTable data = DataTable();
...
// Load Data.
...
// Filter data with input query parameters.
...
// Prepare Ajax JSON Data Result.
result = this.Json(JsonConvert.SerializeObject(data), JsonRequestBehavior.AllowGet);
...
// Return info.
return result;
}
$(document).ready(function ()
{
// Initialization
var customerID = 23;
var firstname = "John";
$.ajax(
{
type: 'POST',
dataType: 'JSON',
url: '/Home/GetData',
data: { customerID: customerID, fname: firstname },
success:
function (response)
{
// Generate HTML table.
convertJsonToHtmlTable(JSON.parse(response), $("#TableId"));
},
error:
function (response)
{
alert("Error: " + response);
}
});
...
});