-1
我正在嘗試創建一個幫助控制器,它將基本上向Web API發出一個GET請求,以創建一個最終將用於返回JSON數據的列表。我在網上找到了一個例子,幾乎可以做我想做的事,除了數據是在控制器內硬編碼的。ASP.NET MVC從Web API調用在幫助控制器中創建列表
控制器(在C#):
public class StudentAPIController : Controller
{
// GET: api/GetAllStudents
[HttpGet]
public IEnumerable<PersonalDetail> GetAllStudents()
{
List<PersonalDetail> students = new List<PersonalDetail>
{
string uri = "URL_OF_API_CALL";
new PersonalDetail{
// Here is where I want to make the API call to fetch the data instead of this hard-coded data
RegNo = "2017-0001",
Name = "Nishan",
Address = "Kathmandu",
PhoneNo = "9849845061",
AdmissionDate = DateTime.Now
},
new PersonalDetail{
RegNo = "2017-0002",
Name = "Namrata Rai",
Address = "Bhaktapur",
PhoneNo = "9849845062",
AdmissionDate = DateTime.Now
},
};
return students;
}
}
任何幫助,不勝感激!
此代碼爲我工作,謝謝! –
你的歡迎傑夫 –