Submit buttons are not working

S A 86 Reputation points
2022-03-29T13:01:33.07+00:00

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");  
    }  
}  

}

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,611 questions
0 comments No comments
{count} votes

Accepted answer
  1. AgaveJoe 28,536 Reputation points
    2022-03-29T14:41:33.403+00:00

    You must follow the openly published naming convention.

    Handlers

    public async Task<IActionResult> OnPostCAsync()
    {                      
            return RedirectToAction("Index", "PersonalPage");
    }
    public async Task<IActionResult> OnPostRAsync()
    {
        return RedirectToAction("Index", "PersonalPage");
    }
    

    Markup

    <form method="post" asp-page-handler="C">               
        <button type="submit" class="btn btn-primary">Submit C</button>                 
    </form>
    
    <form method="post" asp-page-handler="R">
        <button type="submit" class="btn btn-primary">Submit R</button>                 
    </form>
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.