I have a table created in this way
<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>
I would need to add the last two columns and add the totals in Total Price and Total Quantity respectively. My question is how to do it using javascript, from the controller or from the model? This is my model:
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; }
}
And this the controller:
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());
}
Thank you.