I'm having a hard time displaying the values from a list object model to the view.
I've tried to display it using this code
@model IEnumerable<MVC.Models.RootObject>
@foreach (var item in @Model)
{
<li>@item.records</li>
}
But it shows an error
The model item passed into the dictionary is of type 'MVC.Models.RootObject', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MVC.Models.RootObject]'.
Here is my controller that I used to pass data from model to view
var transno = "ST-100420190001";
var client = new HttpClient();
var httpRequestMessage = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("https://myurl.com/" + transno),
Headers = {
{ HttpRequestHeader.Accept.ToString(), "application/json" },
{ HttpRequestHeader.ContentType.ToString(), "application/json"},
{ "client-id", "client_id"},
{ "client-secret","client_secret"},
{ "partner-id","partner_id"},
{ "X-Version", "1" }
}
};
var response = client.SendAsync(httpRequestMessage).Result;
RootObject obj = JsonConvert.DeserializeObject<RootObject>(await
response.Content.ReadAsStringAsync());
return View(obj);
The RootObject model looks like this
public class RootObject
{
public List<Record> records { get; set; }
public int totalRecords { get; set; }
}
Then the Record model looks like this
public class Record
{
public string transferId { get; set; }
public string type { get; set; }
public DateTime createdAt { get; set; }
public string dateUpdated { get; set; }
public string state { get; set; }
public string senderTransferId { get; set; }
}
@modelline in your view file? The error suggests it isIEnumerable<RootObject>and yet you are passing a singleRootObject.