Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a formaction demo #84

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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