After button "Submit C" click it is not directed to OnPostAsyncC and after button "Submit R" click it is not directed to OnPostAsyncR . Below is the code:
@Anonymous
@默 Pro.Pages.PersonalPage.CreateNew
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
ViewData["Title"] = "CreateNew";
Layout = "_Layout";
}
<div class="text-center">
<div class="col-md-8">
<form method="post" asp-page-handler="OnPostAsyncC">
<textarea asp-for="Input.Question1" class="form-control" ></textarea>
<button type="submit" class="btn btn-primary">Submit C</button>
</form>
<form method="post" asp-page-handler="OnPostAsyncR">
<textarea asp-for="Input.Question2" class="form-control"></textarea>
<button type="submit" class="btn btn-primary">Submit R</button>
</form>
</div>
</div>
@section Scripts{
<partial name="_ValidationScriptsPartial" />
}
namespace Pro.Pages.PersonalPage
{
public class CreateNew : PageModel
{
private readonly Data.ApplicationDbContext _context;
private readonly SignInManager<IdentityUser> _signInManager;
private readonly UserManager<IdentityUser> _userManager;
public CreateNew (
Data.ApplicationDbContext context,
UserManager<IdentityUser> userManager,
SignInManager<IdentityUser> signInManager
)
{
_context = context;
_userManager = userManager;
_signInManager = signInManager;
}
[BindProperty]
public InputModel Input { get; set; }
public class InputModel
{
public string Question1 { get; set; }
public string Question2 { get; set; }
}
public IActionResult OnGet(string title)
{
return Page();
}
public async Task<IActionResult> OnPostAsyncC()
{
…
return RedirectToAction("Index", "PersonalPage");
}
public async Task<IActionResult> OnPostAsyncR()
{
…
await _context.SaveChangesAsync();
return RedirectToAction("Index", "PersonalPage");
}
}
}