Hi mahesh213,
Check the below example.
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
var result = GetDetails();
int count = (((JsonResult)result).Data as List<Employee>).Count;
ViewData["Message"] = "Record count : " + count;
return View();
}
public ActionResult GetDetails()
{
var result = GetEmployeeDetails();
return Json(result, JsonRequestBehavior.AllowGet);
}
public List<Employee> GetEmployeeDetails()
{
List<Employee> employees = new List<Employee>()
{
new Employee(){Id=1,Name="aa"},
new Employee(){Id=2,Name="bb"}
};
return employees;
}
public class Employee
{
public int Id;
public string Name;
}
}
View
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
@if (ViewData["Message"] != null)
{
<script type="text/javascript">
window.onload = function () {
alert("@ViewData["Message"]");
};
</script>
}
</body>
</html>
Screenshot