Skip to content

Commit

Permalink
Add a formaction demo
Browse files Browse the repository at this point in the history
  • Loading branch information
haacked committed Dec 12, 2023
1 parent 637efeb commit 3a0cd25
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Pages/Demos/FormAction.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@page
@model DemoWeb.Pages.Demos.FormAction


@{
Layout = "Shared/_Layout";
}

<partial name="Shared/_StatusMessage" model="Model.StatusMessage"/>

<form method="post">
<input type="submit" value="Submit" asp-page-handler="Submit" />
<input type="submit" value="Save" asp-page-handler="Save"/>
</form>
25 changes: 25 additions & 0 deletions Pages/Demos/FormAction.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace DemoWeb.Pages.Demos;

public class FormAction : PageModel
{
[TempData]
public string? StatusMessage { get; set; }


public IActionResult OnPostSubmitAsync()
{
StatusMessage = "Submit button clicked";

return RedirectToPage();
}

public IActionResult OnPostSave()
{
StatusMessage = "Save button clicked";

return RedirectToPage();
}
}
1 change: 1 addition & 0 deletions Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<li><a asp-page="Demos/SubmitButton">Submit Button</a></li>
<li><a asp-page="Demos/RemovedInputs">Removed Inputs</a></li>
<li><a asp-page="Demos/SelectInput">Select Input and Validation Summary</a></li>
<li><a asp-page="Demos/FormAction">Form Action</a></li>
</ul>

@if (Model.StatusMessage != null) {
Expand Down

0 comments on commit 3a0cd25

Please sign in to comment.