Skip to content

Commit

Permalink
Merge pull request #84 from haacked/haacked/39-form-action-fix
Browse files Browse the repository at this point in the history
Add a formaction demo
  • Loading branch information
haacked authored Dec 12, 2023
2 parents 637efeb + 3a0cd25 commit f5ff44d
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 f5ff44d

Please sign in to comment.