我正在 Blazor 中添加一个表单,我正在按照此处指定的说明进行操作
https://docs.microsoft.com/en-us/aspnet/core/blazor/forms-validation?view=aspnetcore-3.0
是否可以添加带有密码掩码的输入。
我尝试添加做类似的事情
public class LoginModel
{
[Required]
public string Username { get; set; }
[Required]
[DataType(DataType.Password)]
public string Password { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但这没有用。有没有办法在输入时隐藏密码?
我在 .NET Core 3.1 中创建了一个 Blazor WebAssembly 托管模板。然后右键单击project.Client/wwwroot/css文件夹并单击Add client side library。然后选择 Font Awesome 库并安装它。我将以 下行添加到index.html<head>。
<link href="css/font-awesome/css/fontawesome.css" rel="stylesheet"/>
Run Code Online (Sandbox Code Playgroud)
我有libman.json的:
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": [
{
"library": "font-awesome@5.11.2",
"destination": "wwwroot/css/font-awesome/"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我仅将以下行添加到默认 Blazor 模板页面Counter.razor(Razor 组件)。IntelliSense 找到字体:
@page "/counter"
<h1>Counter</h1>
<span class="fa fa-save"></span>
@code {}
Run Code Online (Sandbox Code Playgroud)
但我只看到一个正方形:
我正在尝试在 上应用蓝色Theme.of(context).textTheme.headline6,可以通过两种方式完成
Text(
"Hello",
style: Theme.of(context)
.textTheme
.headline6!
.copyWith(color: Colors.blue),
),
Run Code Online (Sandbox Code Playgroud)
或者
Text(
"Hello",
style: Theme.of(context)
.textTheme
.headline6!
.apply(color: Colors.blue),
),
Run Code Online (Sandbox Code Playgroud)
您更喜欢哪一种copyWith或apply方法?
UserManager.FindByEmailAsync返回null,但该用户存在于数据库中。
下面的代码解释了这个奇怪的问题:
var email = info.Principal.FindFirstValue(ClaimTypes.Email);
var test = new Data.ApplicationDbContext().Users.First(x => x.NormalizedEmail == email);
var usermail = await _userManager.FindByEmailAsync(email);
Console.WriteLine(test == null); //false
Console.WriteLine(usermail == null); //true
Run Code Online (Sandbox Code Playgroud)
同样通过_userManager其自身,可以获得所需的用户:
var test = _userManager.Users.FirstOrDefault(x => x.NormalizedEmail == email);
var usermail = await _userManager.FindByEmailAsync(email);
Console.WriteLine(test == null); //false
Console.WriteLine(usermail == null); //true
Run Code Online (Sandbox Code Playgroud)
需要注意的是,用户不是以“常规”方式创建的,而是通过 Data-Seed 创建的(在OnModelCreating):
protected override void OnModelCreating(ModelBuilder builder)
{
var users = new (string email, string name)[] {
("xyz@gmail.com", "admin")
};
var …Run Code Online (Sandbox Code Playgroud) 假设我想使用EditForm,但我希望值绑定在每次用户输入控件时触发,而不是仅仅在模糊时触发。
举个例子,假设我想要一个InputNumber<int>这样做的?我试过使用不同的方法,但bind-Value:event="oninput"没有成功。通过复制 AspNetCore 源代码InputNumber并覆盖/重写一些东西,我终于能够或多或少地获得我想要的东西。
这是我的InputNumber<int>,它实现了我所希望的:
public class MyInputNumber: InputNumber<int>
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(0, "input");
builder.AddAttribute(1, "step", "any");
builder.AddMultipleAttributes(2, AdditionalAttributes);
builder.AddAttribute(3, "type", "number");
builder.AddAttribute(4, "class", CssClass);
builder.AddAttribute(5, "value", FormatValue(CurrentValueAsString));
builder.AddAttribute(6, "oninput", EventCallback.Factory.CreateBinder<string>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));
builder.CloseElement();
}
// Copied from AspNetCore - src/Components/Components/src/BindConverter.cs
private static string FormatValue(string value, CultureInfo culture = null) => FormatStringValueCore(value, culture);
// Copied from AspNetCore - src/Components/Components/src/BindConverter.cs
private static string …Run Code Online (Sandbox Code Playgroud) 随着 ASP.NET Core 3.0 的推出,我尝试在 MVC Core 应用程序中利用服务器端 Blazor 功能。我首先创建一个简单的导航组件,尝试让用户使用指向控制器操作的按钮退出。但是,我遇到了防伪造令牌验证错误,内容如下:
Microsoft.AspNetCore.Mvc.Infrastruct.ControllerActionInvoker:信息:过滤器“Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.ValidateAntiforgeryTokenAuthorizationFilter”处的请求授权失败。
然后服务器返回 HTTP 400 状态代码。
我正在遵循 Blazor 应用程序模板代码(带有 Visual Studio 2019 的 Blazor 版本 0.7.0):
<AuthorizeView>
<Authorized>
<a href="/Account/Manage">Hello, @context.User.Identity.Name!</a>
<form method="post" action="/Account/Logout">
<button type="submit">Sign out</button>
</form>
</Authorized>
<NotAuthorized>
<a href="/Account/Register">Register</a>
<a href="/Account/Login">Log in</a>
</NotAuthorized>
</AuthorizeView>
Run Code Online (Sandbox Code Playgroud)
我的 MVCAccount控制器有一个带有 注释的注销操作[ValidateAntiForgeryToken],如下所示:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Logout()
{
await _signInManager.SignOutAsync();
_logger.LogInformation("User logged out.");
return RedirectToAction(nameof(HomeController.Index), "Home");
}
Run Code Online (Sandbox Code Playgroud)
过去,我会@Html.AntiForgeryToken()在表单中添加一个以符合我注释的注销操作。在较新版本的 ASP.NET Core 中,您不再需要手动添加它,因为它包含在表单标记帮助程序中。但这两种方法似乎都无法在 Blazor 组件中转换或可用。
如何从 Blazor 组件调用此 …
我正在尝试 Microsoft Blazor,在使用表单和验证时,我停止了如何更改默认情况下将在InputText验证状态中添加的默认 CSS 类。
对于InputText默认情况下有错误时的解释,请使用类“ invalid”我想将此类更改为“ is-invalid”
我需要最佳实践。
谢谢,StackOverflow 社区
我有一个ScoreStrategy描述如何计算测验分数的课程:
public class ScoreStrategy
{
public int Id { get; set; }
public int QuizId { get; set; }
[Required]
public Quiz Quiz { get; set; }
public decimal Correct { get; set; }
public decimal Incorrect { get; set; }
public decimal Unattempted { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
三个属性Correct,Incorrect并Unattempted描述要为响应分配多少点。这些点也可以是负的。评分策略适用于测验中的所有问题,因此ScoreStrategy每个测验只能有一个。我有两个子类:
public class DifficultyScoreStrategy : ScoreStrategy
{
public QuestionDifficulty Difficulty { get; set; }
}
public class QuestionScoreStrategy : ScoreStrategy
{ …Run Code Online (Sandbox Code Playgroud) Java 8 中引入的类型Optional<T>主要推荐用于返回类型和结果。因此,每当我在类字段或方法参数中使用它时,我都会在 IntelliJ 中收到警告:
Optional<?>用作字段/参数的类型。
Optional<T>但是,当我在规范构造函数中使用 an 作为记录参数时,我没有收到此警告:
public record AuthenticationResult(
boolean isAuthenticated,
Optional<User> user,
Optional<String> authorizationHeader)
{ }
Run Code Online (Sandbox Code Playgroud)
不使用类型作为参数/字段的做法是否Optional<T>不适用于记录参数,因为字段将始终作为记录自动生成的 getter 方法的返回值进行访问?
或者是因为记录是一项新功能,并且此警告尚未实现,并且在记录中使用可选参数与用作方法参数或字段时具有相同的后果?
asp.net-core ×5
blazor ×5
c# ×5
.net ×4
django ×1
fallback ×1
flutter ×1
font-awesome ×1
java ×1
java-17 ×1
oop ×1
option-type ×1
python ×1
razor ×1
record ×1