I have the controller method GetLayer2(). It is extremely similar to GetLayer0() and GetLayer1()
[HttpGet]
public async Task<JsonResult> GetLayer2(string datePassedIn, string eventType, string driverId)
{
string orgCode = "HVO"; //User.Identity.GetOrgCode();
DateTime? processDate;
DateTime defaultDate = DateTime.Today.AddDays(-1); //default yesterday
if (String.IsNullOrEmpty(datePassedIn))
{
_logger.LogError(String.Format("Date passed in was NULL or empty. Using default date {0}", defaultDate.ToString(inputDateFormat)), null);
processDate = defaultDate;
}
else
{
try
{
processDate = DateTime.ParseExact(datePassedIn, inputDateFormat, cultureProvider);
}
catch (FormatException ex)
{
_logger.LogError(ex, "Error formatting date {datePassedIn} did not match {inputDateFormat}. using default date {defaultDate}", null);
processDate = defaultDate;
}
}
driverId = HttpUtility.UrlDecode(driverId);
IEnumerable<EventTypeLayer2> results = await _context.EventTypeLayer2Results
.FromSql($"usp_dd_EventType_2 @p0, @p1, @p2, @p3", orgCode, processDate, eventType, driverId)
.ToListAsync();
JsonResult jr = Json(results);
return jr;
}
The code can be summed up as:
Originally it was return Json(results);
When debugging the jr
value has the correct Value results
When viewed in the browser (Chrome) in the network tab, I get the correct count of objects, but they are all empty.
How do I get my results?
Edit - added class definition. Although these are EF classes, they are being filled by stored procedures.
[DataContract]
public class EventTypeLayer2
{
[IgnoreDataMember]
[Key]
public Int64 RowId { get; set; }
[Column(TypeName = "varchar(50)")]
public string EventTypeDisplay { get; set; }
[Column(TypeName = "varchar(50)")]
public string EventTypeId { get; set; }
[Column(TypeName = "varchar(20)")]
public string Colour { get; set; }
[Required]
public int Value { get; set; }
[Column(TypeName = "varchar(100)")]
public string DriverId { get; set; }
public int NodeId { get; set; }
[DataType(DataType.DateTime)]
public DateTime StartTime { get; set; }
[DataType(DataType.DateTime)]
public DateTime EndTime { get; set; }
public int FirstLogId { get; set; }
public int LastLogId { get; set; }
public int MinSpeed { get; set; }
public int MaxSpeed { get; set; }
public int AvgSpeed { get; set; }
public int CalcSummOdo { get; set; }
}
You are using [DataContract]
attribute for EventTypeLayer2
class, but you did not provide [DataMember]
attribute for any of the class properties.
From documentation:
You must also apply the DataMemberAttribute to any field, property, or event that holds values you want to serialize.
This is the reason you are getting the right count of the objects, but without any valid member.
Possible solutions:
1) Remove the [DataContract]
attribute from the class. By default, all public properties will be serialized.
2) Add [DataMember]
attribute to properties you wish to serialize.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With