tengo una tabla creada de esta manera
<table class="table table-bordered table-striped">
<tr>
<th>
@Html.DisplayNameFor(model => model.Sale.Date)
</th>
<th>
@Html.DisplayNameFor(model => model.Sale.Warehouse.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Description)
</th>
<th>
@Html.DisplayNameFor(model => model.Price)
</th>
<th>
@Html.DisplayNameFor(model => model.Quantity)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Sale.Date)
</td>
<td>
@Html.DisplayFor(modelItem => item.Sale.Warehouse.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
<td>
@Html.DisplayFor(modelItem => item.Quantity)
</td>
</tr>
}
<tr>
<td colspan="3" align="center">
<strong>Totals</strong>
</td>
<td align="center">
<strong>Total Price</strong>
</td>
<td align="center">
<strong>Total Quantity</strong>
</td>
</tr>
</table>
Necesitaría sumar las dos ultimas columnas y agregar los totales en Total Price y Total Quantity respectivamente. Mi pregunta es como hacerlo mediante javascript, desde el controlador o desde el modelo? Este es mi modelo:
public class SaleDetail
{
[Key]
public int SaleDetailId { get; set; }
[Required(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "ErrorFieldRequired")]
public int SaleId { get; set; }
[Required(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "ErrorFieldRequired")]
public int ProductId { get; set; }
[Required(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "ErrorFieldRequired")]
[StringLength(50, ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "ErrorStringMaxMin", MinimumLength = 1)]
[Display(ResourceType = typeof(Strings), Name = "Product")]
public string Description { get; set; }
[Required(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "ErrorFieldRequired")]
[DisplayFormat(DataFormatString = "{0:C2}", ApplyFormatInEditMode = false)]
[Range(0, double.MaxValue, ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "ErrorDecimal")]
[Display(ResourceType = typeof(Strings), Name = "Price")]
public decimal Price { get; set; }
[Required(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "ErrorFieldRequired")]
[DisplayFormat(DataFormatString = "{0:N2}", ApplyFormatInEditMode = false)]
[Range(0, double.MaxValue, ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "ErrorDecimal")]
[Display(ResourceType = typeof(Strings), Name = "Quantity")]
public double Quantity { get; set; }
public virtual Sale Sale { get; set; }
public virtual Product Product { get; set; }
}
Y este el controlador:
public ActionResult DateSales(string value)
{
var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
var view = db.SaleDetails.Include(s => s.Sale).Where(s => s.Sale.Warehouse.CompanyId == user.CompanyId && s.Sale.Date == DateTime.Today);
return View(view.ToList());
}
Gracias.