Events-MVC (example with htmx)
This commit is contained in:
38
Events-MVC/Events.MVC/Views/Sports/Index.cshtml
Normal file
38
Events-MVC/Events.MVC/Views/Sports/Index.cshtml
Normal file
@@ -0,0 +1,38 @@
|
||||
@model PagedList<Events.MVC.Models.Sports.SportViewModel>
|
||||
|
||||
@{
|
||||
ViewData[Constants.ViewDataKeys.Title] = "Sports";
|
||||
ViewData[Constants.ViewDataKeys.HeaderActionLabel] = "New sport";
|
||||
ViewData[Constants.ViewDataKeys.HeaderActionTarget] = "#create-sport-panel";
|
||||
}
|
||||
|
||||
<div class="d-flex flex-column gap-4">
|
||||
<section id="create-sport-panel" class="collapse">
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-body">
|
||||
<h2 class="h5 mb-3">Add a new sport</h2>
|
||||
<div id="create-sport-form">
|
||||
<partial name="_CreateSportForm" model='new Events.MVC.Models.Sports.SportViewModel()' />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<partial name="_SportsList" model="Model" />
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
document.body.addEventListener(@Html.Raw(System.Text.Json.JsonSerializer.Serialize(Constants.HtmxEvents.SportCreated)), function () {
|
||||
var form = document.querySelector("#create-sport-form form");
|
||||
if (form) {
|
||||
form.reset();
|
||||
}
|
||||
|
||||
var panel = document.getElementById("create-sport-panel");
|
||||
if (panel && window.bootstrap) {
|
||||
bootstrap.Collapse.getOrCreateInstance(panel).hide();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
Reference in New Issue
Block a user