Hi zeeshanpas,
Please refer below sample.
Model
public class Customer
{
public string Name { get; set; }
public string Country { get; set; }
}
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
public JsonResult UpdateCustomers(Customer customer, List<Customer> customers)
{
string returnVal = string.Empty;
return Json(returnVal, JsonRequestBehavior.AllowGet);
}
}
View
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<input type="button" id="btnUpdate" value="Update" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('#btnUpdate').on('click', function () {
var customer = { Name: "John Hammond", Country: "United States" };
var customers = [];
customers.push({ Name: "Mudassar Khan", Country: "India" });
customers.push({ Name: "Robert", Country: "France" });
manageAddUpadte("/Home/UpdateCustomers", customer, customers);
});
});
function manageAddUpadte(url, customer, customers) {
$.ajax({
type: "POST",
url: url,
data: JSON.stringify({ customer: customer, customers: customers }),
contentType: "application/json; Charset:utf-8",
dataType: "json",
success: function (data) {
alert(data);
},
error: function (data) {
alert(data.responseText);
}
});
}
</script>
</body>
</html>
Screenshot