Wie kann ich die Summe der Werte im MVC-Ansicht?
Wie kann ich die Summe der Werte im MVC-Ansicht?
Ich möchte die Summe aller KwotaOplaty Datensätze werden nun angezeigt.
Bemerken, dass ich mit Hilfe der SUCHE (am controller) wenn ich also die Suche nach bestimmten Datensätzen möchte ich Summe Sie alle.
Controller:
public ActionResult Index(string oplataTyp, string szukajRej)
{
var TypLista = new List<RodzajOplaty>();
var TypWyszukaj = from d in db.Oplaty orderby d.RodzajOplaty select d.RodzajOplaty;
TypLista.AddRange(TypWyszukaj.Distinct());
ViewBag.oplataTyp = new SelectList(TypLista);
var oplaty = from p in db.Oplaty select p;
RodzajOplaty RodzajOplaty;
if (Enum.TryParse<RodzajOplaty>(oplataTyp, out RodzajOplaty))
{
oplaty = oplaty.Where(x => x.RodzajOplaty == RodzajOplaty);
}
if (!String.IsNullOrEmpty(szukajRej))
{
oplaty = oplaty.Where(s => s.TablicaRejstracyjna.Contains(szukajRej));
}
return View(oplaty.ToList());
}
Anzeigen:
@model IEnumerable<AutoMonit.Models.Oplata>
<h2>Zestawienie opłat pojazdów</h2>
<p>
@Html.ActionLink("Utwórz", "Create")
</p>
@*@using (Html.BeginForm())
{
<div>Numer rejestracyjny: </div>
<div>@Html.TextBox("NumerRej")</div>
<input type="submit" value="Szukaj" />
}*@
@using (Html.BeginForm("Index", "Oplatas", FormMethod.Get))
{
<p>
Rodzaj oplaty: @Html.DropDownList("oplataTyp", "Wszystkie")<br />
Numer rejestracyjny: @Html.TextBox("szukajRej") <br />
<input type="submit" value="Szukaj" />
</p>
}
<br />
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.TablicaRejstracyjna)
</th>
<th>
@Html.DisplayNameFor(model => model.Pojazd.Marka)
</th>
<th>
@Html.DisplayNameFor(model => model.DataOplaty)
</th>
<th>
@Html.DisplayNameFor(model => model.PrzebiegOplaty)
</th>
<th>
@Html.DisplayNameFor(model => model.RodzajOplaty)
</th>
<th>
@Html.DisplayNameFor(model => model.KwotaOplaty)
</th>
<th>
@Html.DisplayNameFor(model => model.DodatkoweInformacjeOplaty)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.TablicaRejstracyjna)
</td>
<td>
@Html.DisplayFor(modelItem => item.Pojazd.Marka)
</td>
<td>
@Html.DisplayFor(modelItem => item.DataOplaty)
</td>
<td>
@Html.DisplayFor(modelItem => item.PrzebiegOplaty)
</td>
<td>
@Html.DisplayFor(modelItem => item.RodzajOplaty)
</td>
<td>
@Html.DisplayFor(modelItem => item.KwotaOplaty)
</td>
<td>
@Html.DisplayFor(modelItem => item.DodatkoweInformacjeOplaty)
</td>
<td>
@Html.ActionLink("Edytuj", "Edit", new { id=item.ID }) |
@Html.ActionLink("Szczegóły", "Details", new { id=item.ID }) |
@Html.ActionLink("Usuń", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>
<hr />
<h2>Suma kosztów:</h2>
@*Here i want to display sum*@
Summe Sie in der Steuerung und übergeben Sie den Wert, um die Ansicht (als eine Eigenschaft des view-Modell oder als
ViewBag
Eigenschaft)
InformationsquelleAutor DiPix | 2015-11-11
Du musst angemeldet sein, um einen Kommentar abzugeben.
Sollten Sie in der Lage sein, mit Sum-Methode und setzen das Ergebnis mit dem Wert in einem ViewBag Wert und referenzieren es mit Razor. Es sollte so etwas wie dieses:
In der Steuerung
In der Ansicht
Denken Sie daran,
InformationsquelleAutor Frankely Diaz
ja, Sie nicht wirklich brauchen, das Display Helfer.. man kann nur die Ausgabe der Summe
Danke @JamieD77. Ich stecken bleiben, versuchen, etwas zu tun, wie Wert++ . Deine Antwort wies mich in die richtige Richtung: @(Modell.element + 1)
InformationsquelleAutor JamieD77