I am trying to add common values to any numeric column in a table in MVC and display the totals in the title bar. For example, I would like to add all the values in the TotalCashStake column and display that number in the title bar. I am completely new to MVC, and I'm not sure how to implement this.
This is the index.cshtml page:

This is my source code for the index.cshtml page:
@model IEnumerable<DailyReport>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
@using (Html.BeginForm())
{
<p>
Start Date: @Html.TextBox("StartDate") <br />
<br />
End Date: @Html.TextBox("EndDate") <br />
<br />
<input type="submit" value="Filter" />
</p>
}
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.DailyReportDate)
</th>
<th>
@Html.DisplayNameFor(model => model.BettingShop)
</th>
<th>
@Html.DisplayNameFor(model => model.Estate)
</th>
<th>
@Html.DisplayNameFor(model => model.SisSrNumber)
</th>
<th>
@Html.DisplayNameFor(model => model.ShopBalance)
</th>
<th>
@Html.DisplayNameFor(model => model.TotalCashStake)
</th>
<th>
@Html.DisplayNameFor(model => model.TotalOtherCashOut)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.DailyReportDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.BettingShop)
</td>
<td>
@Html.DisplayFor(modelItem => item.Estate)
</td>
<td>
@Html.DisplayFor(modelItem => item.SisSrNumber)
</td>
<td>
@Html.DisplayFor(modelItem => item.ShopBalance)
</td>
<td>
@Html.DisplayFor(modelItem => item.TotalCashStake)
</td>
<td>
@Html.DisplayFor(modelItem => item.TotalOtherCashOut)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.DailyReportId }) |
@Html.ActionLink("Details", "Details", new { id=item.DailyReportId }) |
@Html.ActionLink("Delete", "Delete", new { id=item.DailyReportId })
</td>
</tr>
}
</table>
And this is the code for my controller:
namespace Reporting.Controllers
{
public class DailyReportController : Controller
{
private RiskEntities db = new RiskEntities();
public ActionResult Index(DateTime? startDate, DateTime? endDate)
{
if (startDate == null || endDate == null)
{
return View(db.DailyReports.ToList());
}
var endDateToUse = (DateTime) endDate;
endDateToUse = endDateToUse.AddDays(+1);
var dailyReports = (from dr in db.DailyReports
where dr.DailyReportDate >= startDate
&& dr.DailyReportDate <= endDateToUse
select dr);
return View(dailyReports.ToList());
}
public ActionResult Details(Guid? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
DailyReport dailyreport = db.DailyReports.Find(id);
if (dailyreport == null)
{
return HttpNotFound();
}
return View(dailyreport);
}
public ActionResult Create()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include="DailyReportId,DailyReportDate,BettingShop,Estate,SisSrNumber,ShopBalance,TotalCashStake,TotalOtherCashOut,TotalPhoneAccountCashDeposit,TotalPhoneAccountCashWithdrawl,TotalCashFromBank,TotalTransfersFromOtherShops,TotalPaidByOtherShops,TotalCashToBank,TotalTransfersToOtherShops,TotalPaidHereForOtherShops,TotalExpenses,TotalOtherCashIn,TotalPayoutCancellations,TotalStakes,TotalStakeLessVoids,TotalVoid,TotalPayouts,TotalCreditPayouts,TotalCreditStakes,TotalCreditVoids,TotalEndFloatActual,PendingPayouts6Days,PendingPayouts1Day,TotalCashIn,TotalCashPayoutIncludingVoids,TotalCashPayoutExcludingVoids,TotalCashPayoutForHere,NumberCashSlips,NumberAccountSlips,NumberCashSlipsPaidForOtherDays,NumberCashSlipsPaidForToday,TotalTillTransferIn,TotalTillTransferOut,TotalCashOut,TotalCashLeftHandSide,TotalCashRightHandSide")] DailyReport dailyreport)
{
if (ModelState.IsValid)
{
dailyreport.DailyReportId = Guid.NewGuid();
db.DailyReports.Add(dailyreport);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(dailyreport);
}
public ActionResult Edit(Guid? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
DailyReport dailyreport = db.DailyReports.Find(id);
if (dailyreport == null)
{
return HttpNotFound();
}
return View(dailyreport);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include="DailyReportId,DailyReportDate,BettingShop,Estate,SisSrNumber,ShopBalance,TotalCashStake,TotalOtherCashOut,TotalPhoneAccountCashDeposit,TotalPhoneAccountCashWithdrawl,TotalCashFromBank,TotalTransfersFromOtherShops,TotalPaidByOtherShops,TotalCashToBank,TotalTransfersToOtherShops,TotalPaidHereForOtherShops,TotalExpenses,TotalOtherCashIn,TotalPayoutCancellations,TotalStakes,TotalStakeLessVoids,TotalVoid,TotalPayouts,TotalCreditPayouts,TotalCreditStakes,TotalCreditVoids,TotalEndFloatActual,PendingPayouts6Days,PendingPayouts1Day,TotalCashIn,TotalCashPayoutIncludingVoids,TotalCashPayoutExcludingVoids,TotalCashPayoutForHere,NumberCashSlips,NumberAccountSlips,NumberCashSlipsPaidForOtherDays,NumberCashSlipsPaidForToday,TotalTillTransferIn,TotalTillTransferOut,TotalCashOut,TotalCashLeftHandSide,TotalCashRightHandSide")] DailyReport dailyreport)
{
if (ModelState.IsValid)
{
db.Entry(dailyreport).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(dailyreport);
}
public ActionResult Delete(Guid? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
DailyReport dailyreport = db.DailyReports.Find(id);
if (dailyreport == null)
{
return HttpNotFound();
}
return View(dailyreport);
}
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(Guid id)
{
DailyReport dailyreport = db.DailyReports.Find(id);
db.DailyReports.Remove(dailyreport);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}