I tried many things but I'm still unable to display data in View. I'm only getting a null result in View page. When I debug using a break point, I can clearly see data in the variables but can't return it in View. Seems like I need a List...
The aim is to return json data in a HTML View.
public async Task<ActionResult> GetAPIStringAsync(Students model)
{
HttpClient client = new HttpClient();
string APIdatas = null;
HttpResponseMessage response = await client.GetAsync("https://jsonplaceholder.typicode.com/todos/");
if (response.IsSuccessStatusCode)
{
APIdatas = await response.Content.ReadAsStringAsync();
}
var stringJson = JsonConvert.DeserializeObject<IEnumerable<Students>>(APIdatas);
return Json(model, JsonRequestBehavior.AllowGet);
return View();
}
public class Students
{
public int Id { get; set; }
public string Title { get; set; }
public string Url { get; set; }
}
and in my View, I have this :
@model IEnumerable<AutoMobile.Web.Models.Manage.Students>
@foreach (var item in Model.OrderBy(x => x.Id))
{
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.Url)
</td>
}
return View(model);