Kurse:Tag Helpers: Unterschied zwischen den Versionen
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
= ASP.NET Core MVC Tag Helpers – Code Spickzettel = | = ASP.NET Core MVC Tag Helpers – Code Spickzettel = | ||
Zeile 145: | Zeile 143: | ||
== Validierung == | == Validierung == | ||
< | <pre> | ||
<!-- Feld-spezifische Fehlermeldung --> | <!-- Feld-spezifische Fehlermeldung --> | ||
<span asp-validation-for="Name"></span> | <span asp-validation-for="Name"></span> | ||
Zeile 151: | Zeile 149: | ||
<!-- Zusammenfassung aller Validierungsfehler --> | <!-- Zusammenfassung aller Validierungsfehler --> | ||
<div asp-validation-summary="All"></div> | <div asp-validation-summary="All"></div> | ||
</ | </pre> | ||
== Partial Views == | == Partial Views == |
Aktuelle Version vom 29. Juni 2025, 20:28 Uhr
ASP.NET Core MVC Tag Helpers – Code Spickzettel
Allgemeine Verwendung
<a asp-controller="Home" asp-action="Index">Startseite</a>
<form asp-controller="Products" asp-action="Create" method="post">
</form>
<input asp-for="ProductName" class="form-control" />
<select asp-for="CategoryId" asp-items="Model.Categories"></select>
<label asp-for="ProductName"></label>
<cache expires-after="@TimeSpan.FromMinutes(10)">
Inhalt zum Zwischenspeichern
</cache>
<environment names="Development">
<script src="~/lib/dev-only.js"></script>
</environment>
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
CRUD Beispiele
Index (Lesen)
<a asp-action="Create">Erstellen</a>
<a asp-action="Edit" asp-route-id="@item.Id">Bearbeiten</a>
<a asp-action="Delete" asp-route-id="@item.Id">Löschen</a>
<form asp-action="Index" method="get">
<input type="text" name="searchString" />
<button type="submit">Suchen</button>
</form>
Create / Edit (Erstellen / Bearbeiten)
<form asp-action="Create" method="post">
<label asp-for="Name"></label>
<input asp-for="Name" />
<label asp-for="Description"></label>
<textarea asp-for="Description"></textarea>
<label asp-for="CategoryId"></label>
<select asp-for="CategoryId" asp-items="ViewBag.Categories"></select>
<button type="submit">Speichern</button>
</form>
Delete (Löschen)
<form asp-action="Delete" asp-route-id="@Model.Id" method="post">
<button type="submit">Löschen</button>
</form>
Validierung
<!-- Feld-spezifische Fehlermeldung --> <span asp-validation-for="Name"></span> <!-- Zusammenfassung aller Validierungsfehler --> <div asp-validation-summary="All"></div>
Partial Views
<partial name="_GridColumnHeader" />
CRUD Beispiele
Index (Lesen)
<a asp-action="Create">Erstellen</a>
<a asp-action="Edit" asp-route-id="@item.Id">Bearbeiten</a>
<a asp-action="Delete" asp-route-id="@item.Id">Löschen</a>
<form asp-action="Index" method="get">
<input type="text" name="searchString" />
<button type="submit">Suchen</button>
</form>
Create / Edit (Erstellen / Bearbeiten)
<form asp-action="Create" method="post">
<label asp-for="Name"></label>
<input asp-for="Name" />
<label asp-for="Description"></label>
<textarea asp-for="Description"></textarea>
<label asp-for="CategoryId"></label>
<select asp-for="CategoryId" asp-items="ViewBag.Categories"></select>
<button type="submit">Speichern</button>
</form>
Delete (Löschen)
<form asp-action="Delete" asp-route-id="@Model.Id" method="post">
<button type="submit">Löschen</button>
</form>
Validierung
<!-- Feld-spezifische Fehlermeldung --> <span asp-validation-for="Name"></span> <!-- Zusammenfassung aller Validierungsfehler --> <div asp-validation-summary="All"></div>
Partial Views
<partial name="_GridColumnHeader" />