【发布时间】:2020-03-11 11:46:23
【问题描述】:
尝试在 VS2019 for Mac 中构建 Blazor 博客引擎的公共存储库时遇到以下编译错误,不知道为什么以及如何解决它:
错误 CS1503:参数 3:无法从“方法组”转换为 '布尔'(CS1503)
在以下 Razor 页面中:
@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>
CS 文件如下所示:
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;
}
}
}
}
你能解释一下为什么会发生这种情况以及如何解决它吗?
解决方案:
<button class="btn btn-primary" @onclick="@Login">Login</button>
缺少登录方法的括号:
<button class="btn btn-primary" @onclick="@Login()">Login</button>
【问题讨论】:
标签: c# .net asp.net-core razor blazor