4

While trying to Build a public Repo of a Blazor Blog Engine in VS2019 for Mac I encounter the following compile Error and don't know why and how to solve it:

Error CS1503: Argument 3: cannot convert from 'method group' to 'bool' (CS1503)

In the following Razor Page:

@layout MainLayout
@inherits LoginModel

<WdHeader Heading="WordDaze" SubHeading="Please Enter Your Login Details"></WdHeader>

<div class="container">
<div class="row">
    <div class="col-md-4 offset-md-4">
        <div class="editor">
            @if (ShowLoginFailed)
            {
                <div class="alert alert-danger">
                    Login attempt failed.
                </div>
            }
            <input type="text" @bind=@LoginDetails.Username placeholder="Username" class="form-control" />
            <input type="password" @bind=@LoginDetails.Password placeholder="Password" class="form-control" />
            <button class="btn btn-primary" @onclick="@Login">Login</button>
        </div>
    </div>
</div>

The CS File looks like this:

using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using WordDaze.Shared;


namespace WordDaze.Client.Features.Login
{
    public class LoginModel : ComponentBase
    {
        [Inject] private AppState _appState { get; set; }
        [Inject] private NavigationManager _navigationManager { get; set; }

        protected LoginDetails LoginDetails { get; set; } = new LoginDetails();
        protected bool ShowLoginFailed { get; set; }

        protected async Task Login()
        {
            await _appState.Login(LoginDetails);

            if (_appState.IsLoggedIn)
            {
                _navigationManager.NavigateTo("/");
            }
            else
            {
                ShowLoginFailed = true;
            }
        }
    }
}

Can you please explain me why this happens and how to solve it?

Solution:

<button class="btn btn-primary" @onclick="@Login">Login</button>

was missing the Parentheses of the Login Method:

<button class="btn btn-primary" @onclick="@Login()">Login</button>
Maximus
  • 41
  • 1
  • 6

1 Answers1

4

Change the <button> so that the @onclick method doesn't have the @:

<button class="btn btn-primary" @onclick="Login">Login</button>
user3071284
  • 6,955
  • 6
  • 43
  • 57