Issue with bind-Value, object failing to be created

I’m working on a Blazor application and I’m having trouble with my login form. The LoginModel object is always empty when it’s passed to my HandleLogin method, causing the login process to fail. Additionally, I’m encountering the following error:

Severity    Code    Description    Project    File    Line    Suppression State
Error (active)    RZ9991    The attribute names could not be inferred from bind attribute 'bind-Value'. Bind attributes should be of the form 'bind' or 'bind-value' along with their corresponding optional parameters like 'bind-value:event', 'bind:format' etc.

Here is the relevant part of my code:

`
@page "/login"
@layout BTDMiddleware___Frontend.Components.Layout.LoginLayout
@inject BTDMiddleware___Frontend.Components.AuthService AuthService
@inject NavigationManager Navigation
@inject HttpClient HttpClient
@using BTDMiddleware___Frontend.Components.Modals
@using BTDMiddleware___Frontend.Components.Model

<style>
    /* Styling code omitted for brevity */
</style>

<div class="login-container">
    <div class="login-left">
        <h1>Welcome Page</h1>
        <p>Sign in to continue access</p>
        <p>Server URI: @serverUri</p>
        <p>HttpClient Base Address: @httpClientBaseAddress</p>
    </div>
    <div class="login-right">
        <div class="login-card">
            <h3>Sign In</h3>
            <div class="social-login">
                <a href="#">Sign In with Azure</a>
            </div>
            <div class="separator">
                <div class="separator-line"></div>
                <div class="separator-text">OR</div>
                <div class="separator-line"></div>
            </div>
            <EditForm Model="@loginModel" OnValidSubmit="@HandleLogin" FormName="loginForm">
                <DataAnnotationsValidator />
                <ValidationSummary />
                <div>
                    <label>Username:</label>
                    <InputText @bind-Value="loginModel.Username" class="form-control" />
                </div>
                <div>
                    <label>Password:</label>
                    <InputText @bind-Value="loginModel.Password" type="password" class="form-control" />
                </div>
                <button type="submit">Continue</button>
            </EditForm>
            <div class="sign-up">
                Or Sign Up Using
                <a href="/signup">SIGN UP</a>
            </div>
        </div>
    </div>
</div>

<ErrorModal Show="@showErrorModal" ShowChanged="@OnShowChanged" ErrorMessage="@errorMessage" />

@code {
    private LoginModel loginModel = new LoginModel();
    private bool showErrorModal = false;
    private string errorMessage = string.Empty;
    private string serverUri;
    private string httpClientBaseAddress;

    protected override void OnInitialized()
    {
        serverUri = Navigation.BaseUri;
        httpClientBaseAddress = HttpClient.BaseAddress?.ToString() ?? "No base address set";
        Console.WriteLine($"Server URI: {serverUri}");
        Console.WriteLine($"HttpClient Base Address: {httpClientBaseAddress}");
    }

    private async Task HandleLogin()
    {
        Console.WriteLine("HandleLogin method called");
        Console.WriteLine($"Attempting login with Username: {loginModel.Username}, Password: {loginModel.Password}");
        Console.WriteLine($"Server URI: {serverUri}");
        Console.WriteLine($"HttpClient Base Address: {httpClientBaseAddress}");

        try
        {
            var response = await AuthService.Login(loginModel);
            Console.WriteLine($"Login request sent. Status Code: {response.StatusCode}");

            if (response.IsSuccessStatusCode)
            {
                if (await AuthService.IsAuthenticated())
                {
                    Navigation.NavigateTo("/");
                }
                else
                {
                    errorMessage = "Invalid username or password.";
                    showErrorModal = true;
                }
            }
            else
            {
                var content = await response.Content.ReadAsStringAsync();
                Console.WriteLine($"Login request failed. Status Code: {response.StatusCode}, Reason: {content}");
                errorMessage = "An error occurred during login. Please try again.";
                showErrorModal = true;
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Exception occurred during login: {ex.Message}");
            errorMessage = "An error occurred during login. Please try again.";
            showErrorModal = true;
        }
    }

    private async Task OnShowChanged(bool value)
    {
        showErrorModal = value;
        await Task.CompletedTask;
    }
}
`

In my HandleLogin method, loginModel.Username and loginModel.Password are always null or empty, even though I have bound them correctly in the form using @bind-Value.

What could be causing the LoginModel object to be empty when the form is submitted, and how can I fix this issue? Additionally, how can I resolve the RZ9991 error regarding the @bind-Value attribute?

Additional Information:

  • I’m using Blazor Server.
  • The login form is displayed correctly and does not show any validation errors.
  • The HandleLogin method is triggered as expected when the form is submitted.
  • Any help would be greatly appreciated!

I modified the Blazor login page to handle form input values using local variables instead of directly binding the loginModel. The goal was to avoid binding issues by manually creating the loginModel object during form submission.

**What I Tried:
**

  1. Removed the binding of loginModel to the input fields.
  2. Introduced local variables username and password to hold the input values.
  3. Updated the HandleLogin method to create and populate the loginModel object with these local variables during form submission.

**Expected Outcome:
**I expected the form to accept user inputs for the username and password, store these values in the local variables, and then use these values to create a loginModel object during form submission. This object would be used to send a login request to the server.

**Actual Result:
**The form successfully accepted and stored the input values in the local variables. During form submission, the loginModel was correctly created and populated with these values, and the login request was sent as expected without any binding issues.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật