its an mvc project with a restapi thingo, im working on a get that returns all results from a db, here is everything possibly related to the fucking issue, ive been going insane, absolutely any help is appreciated
[HttpGet]
public IActionResult Index()
{
List<AccountDisplayModel> accountList = new List<AccountDisplayModel>();
HttpResponseMessage response = _client.GetAsync(_client.BaseAddress + "accounts").Result;
if (response.IsSuccessStatusCode)
{
string data = response.Content.ReadAsStringAsync().Result;
try
{
accountList = JsonConvert.DeserializeObject<List<AccountDisplayModel>>(data);
}
catch (JsonSerializationException ex)
{
// Log or handle the exception
Console.WriteLine($"Serialization error: {ex.Message}");
}
}
return View(accountList);
}
This is the model i use for this
public class AccountDisplayModel
{
public int AccountId { get; set; }
[Required][StringLength(50)]public string? Name { get; set; }
[Required][StringLength(30)] public string AccountName { get; set; }
[Required] public decimal Balance { get; set; }
[Required][StringLength(15)] public string Currency { get; set; }
public DateTime CreatedDate{get; set;}
}
this is the model i use for everthing else
public class AccountModel
{
public int AccountId { get; set; }
public int UserId { get; set; }
[ForeignKey("UserId")] public UserModel? User { get; set; }
[Required][StringLength(30)] public string AccountName { get; set; }
[Required] public decimal Balance { get; set; }
[Required][StringLength(15)] public string Currency { get; set; }
public DateTime CreatedDate{get; set;}
}
this is the value returned TO THE MVC by my api ( highlighted is the value that is always null)
value returned from my api itself
both of these values are correct,
and then desirialization happens
and the value is null…?????
any help please
ive triple checked every single possible thing, no spelling mistakes, ive checked a similiar project and it works over there, i just do not understand why it refuses to pass the value to UserName in AccountDisplayModel, even though my other Models work in the rest of my project this one just refuses to collaborate with me
user25269189 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.