Home > other >  C# Blazor button click returns HTTP error 400
C# Blazor button click returns HTTP error 400

Time:11-01

When I click on the button i get the following error This page isn’t working If the problem continues, contact the site owner.

Please any advice ?

I want the button to execute the function and stay on the same page.

HTTP ERROR 400

Login.razor.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace W3SHARE_Interface.Pages.Authentication
{
    public partial class Login
    {
        private void LoginBTN()
        {

        }
        
    }
}

Login.razor

@page "/"

    <body>
        <div id="login">
            <h3 class="text-center text-white pt-5">Login form</h3>
            <div class="container">
                <div id="login-row" class="row justify-content-center align-items-center">
                    <div id="login-column" class="col-md-6">
                        <div id="login-box" class="col-md-12">
                            <form id="login-form" class="form" action="" method="post">

                                <h3 class="text-center text-info">Login</h3>

                                <div class="form-group">
                                    <label for="email" class="text-info">Email:</label><br>
                                    <input type="text" name="email" id="email" class="form-control">
                                </div>

                                <div class="form-group">
                                    <label for="password" class="text-info">Password:</label><br>
                                    <input type="text" name="password" id="password" class="form-control">
                                </div>

                                <div class="form-group">
                                    <label for="remember-me" class="text-info"><span>Remember me</span> <span><input id="remember-me" name="remember-me" type="checkbox"></span></label><br>
                                    <input name="submit" class="btn btn-info btn-md" value="Login" type="submit" @onclick="LoginBTN">
                                </div>

                                <div id="register-link" class="text-right">
                                    <a href="/Register" class="text-info">Register here</a>
                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>


CodePudding user response:

Is it because your form has an empty action attribute? Or be ause your loginbtn method is private? Or because you are sending data to a method without any params?

Perhaps increase the log level to verbose, it also sounds like a model validation problem

CodePudding user response:

I think this is because you are using an input type SUBMIT which is not posting anywhere handled. Try replacing your standard form with EditForm.

  • Related