Use the below code
CONTROLLER
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
public class App1Controller : Controller
{
public ActionResult Index()
{
return View();
}
[HttpGet]
public JsonResult GetCustomerModelList()
{
CustomerModelList oBOCustomerModelList = new CustomerModelList();
for (int i = 2; i < 10; i++)
oBOCustomerModelList.Add(new CustomerModel { Id = i, Salary = i * 2 + 300, cusName = "CUST " + i.ToString() });
return Json(oBOCustomerModelList, JsonRequestBehavior.AllowGet);
}
}
}
VIEW
@{
ViewBag.Title = "Index";
Layout=null;
}
<script type="text/javascript" src="~/Scripts/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function () {
$('#btnShowAll').click(function () {
$.ajax({
type: "GET",
url: "./App1/GetCustomerModelList",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var content = '<table style="border-spacing:0;" border="1"><trstyle="font-weight:200;><td>ID</td><td>Salary</td><td>Name</td></tr>';
$(response).each(function () {
content = content + '<tr><td>' + this.Id + '</td><td>' + this.Salary + '</td><td>' + this.cusName + '</td></tr>';
});
content = content + '</table>';
$('#dvData').html(content);
}
});
});
});
</script>
<input type="button" id="btnShowAll" value="Show All"/>
<div id="dvData"></div>
MODEL
public class CustomerModel
{
public int Id { get; set; }
public int Salary { get; set; }
public string cusName { get; set; }
}
public class CustomerModelList : List<CustomerModel>
{
}