I have made a project as per the requirements. I create a controller of API but doesn't show the data in the view. In the below picture the view didn't access the data from the controller. If someone knows about this please let me know.
Thanks.

I have made a project as per the requirements. I create a controller of API but doesn't show the data in the view. In the below picture the view didn't access the data from the controller. If someone knows about this please let me know.
Thanks.

Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Farhan AhmedPosted Mar 25, 2022, 11:09 AM
Sachin SinghPosted Mar 26, 2022, 6:33 AM
Datatable needs Json data.emps= new List()
Id
Name
@item.Id
@item.Name
You have two option to use datatable
1st:- Convert table to datatable (not recommended by me)
public ActionResult Index()
{
List
{
id=1,Name="Sachin",
id=2,Name="Rakesh"
}
return View(emps);
}
// your class
public class Employee
{
public int id{get;set;}
public string Name {get;set;}
}
@model IEnumerable
@foreach(var item in Model)
{
}
2nd Option (Recommended):-emps= new List()
public ActionResult Index()
{
return View();
}
public ActionResult GetEmployees()
{
List
{
id=1,Name="Sachin",
id=2,Name="Rakesh"
}
return Json(emps,JsonRequestBehavior.AllowGet);
}
}
// your class
public class Employee
{
public int id{get;set;}
public string Name {get;set;}
}
// Index view