11
I have searched high and low and tried various patterns but it seems I cannot get it to work right. The one time I got it to work there was so much code I figured there had to be an easier way and now its completely broken. my goal... to understand the basics of how to use KO Mapping and MVC to have this grid load.. and possibly use a form to update it. I cannot find any examples that are working for my situation. Here is what I am down too now.
Here is my Action:
public JsonResult List()
{
var result = new JsonResult();
result.Data = _service.GetWeightStats();
return Json(result, JsonRequestBehavior.AllowGet);
}
Here is my Class:
public class WeightStat
{
public int Id { get; set; }
[Required]
public double Weight { get; set; }
public double? Neck { get; set; }
public double? Chest { get; set; }
public double? Bicept { get; set; }
public double? Waist { get; set; }
public double? Hip { get; set; }
public double? Thigh { get; set; }
public double? Calf { get; set; }
[Required]
public DateTime Date { get; set; }
[Required]
public string TimeOfDay { get; set; }
[Required]
public string DietBehavior { get; set; }
}
Here is my template line:
<tbody data-bind='template: {name: "statRowTemplate", foreach: data.Data }'></tbody>
Here is my template:
<script id="statRowTemplate" type="text/html">
<tr data-bind="attr: { id: Id }">
<td><span data-bind="text: Date"></span></td>
<td><span data-bind="text: TimeOfDay"></span></td>
<td><span data-bind="text: DietBehavior"></span></td>
<td><span data-bind="text: Weight"></span></td>
<td><span data-bind="text: Neck">&l