Continuing from my previous query here, I am working with a model called SchoolTestsPerModulePerStudent which looks like this:
public partial class SchoolTestsPerModulePerStudent
{
public long StudentID { get; set; }
public long ModuleID { get; set; }
public System.DateTime TestDate { get; set; }
public int TestResult { get; set; }
}
In the previous question, I shared a code snippet from a controller function:
var query = from b in db.SchoolTestsPerModulePerStudent
where b.StudentID.Equals(2)
select b;
return View(query.ToArray());
The issue I am facing now is the need to split the results from 'b' into two separate arrays that I can use in JavaScript within my view.
My current challenges are:
1. Is it possible to split the array of SchoolTestsPerModulePerStudent records into two separate arrays, one containing only TestDate and the other containing only TestResult? I am struggling to find a way to achieve this.
2. How can I return both of these new arrays using only one function? I aim to avoid running the query again (which may cause a delay) and ensure that the elements in both arrays are in the same order.
Furthermore, based on the advice I received in my previous query, I understand that the arrays should be returned as JSON using @Json.Encode(Model)
. Can I then use @Json.Encode(TestDatesArray)
and @Json.Encode(TestResultsArray)
in this scenario?