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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Farhan AhmedRank #73 · 25K reputationPosted Mar 25, 2022, 7:09 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Mar 26, 2022, 2:33 AM EDT
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