Home > Net >  Stack Overflow on form submit
Stack Overflow on form submit

Time:12-17

I am creating two login forms, Razor Page,

The Page Model Login.cshtml.cs is as follow

        public void OnGet()
        {
 
        }

        [BindProperty]
        public Admin Admin { get; set; }
        [BindProperty]
        public Member Member { get; set; }

        public IActionResult OnPostManager()
        {
            return RedirectToPage("../Index");
        }

        public IActionResult OnPostMember()
        {
            return RedirectToPage("../Index");
        }

This is the Login.cshtml file

<div >

    <form method="post">
        <input type="hidden" asp-for="Admin.Id" />
        <input type="text" asp-for="Admin.Name" />
        <button type="button" asp-page_handler="Manager">Login</button>
    </form>

    <form method="post">
        <input type="hidden" asp-for="Member.Id" />
        <input type="text" asp-for="Member.Name" />
        <button type="button" asp-page_handler="Member">Login</button>
    </form>


</div>

The problem is When I click the Login button for Member, it redirects successfully to Index Page. But when I click on login for admin, the web application crashes and It shows error StackOverflow [just the keyword].

I have tried;

  1. deleting the bin and obj.
  2. deleting the IISExpress folder and .vs folder
  3. restart the visual studio
  4. restarting the computer
  5. deleting the %temp% file

but no solution.

[note: this is the simplified code from the original file, the original file contain more CSS and icons]

CodePudding user response:

    <form method="post" >
                                    <div >
                                        <div ><span
                                                ></span></div>
                                        <input type="text"  asp-for="FirstName" placeholder="FirstName"
                                            required>
                                    </div>
                                    <div >
                                        <div ><span
                                                ></span></div>
                                        <input type="password"  asp-for="LastName"
                                            placeholder="LastName" required>
                                    </div>
                                    <div >
                                        <button type="submit" id="submitBtn"
                                            >Go!</button>
                                    </div>
                                </form>

    //Login.cshtml.cs
    
    [BindProperty]
    public string FirstName { get; set; }

    [BindProperty]
    public string LastName { get; set; }

public async Task<IActionResult> OnPostAsync()
        {
            LoginRequest request = new LoginRequest
            {
                FirstName = FirstName,
                LastName = LastName,
            };

            .
            .
            .
            
            if (..)
            {
                return RedirectToPage("./Home");
            }

            
            return Page();
        }

CodePudding user response:

In Razor Page, there is single post available so they have one option using ajax you could post other wise you write under post method using with c#

  • Related