Answers for "using ajax in javascript value view to controller in c#"

C#
0

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);  
                }  
        });  
...   
  
});
Posted by: Guest on August-28-2021

Code answers related to "using ajax in javascript value view to controller in c#"

C# Answers by Framework

Browse Popular Code Answers by Language