[英]FluentValidation "Error cs0103 the name 'x' does not exist in the current context" .asp.net core 2.1
Issue问题
I am receiving the following error when using FluentValidation.AspNetCore (ver 8.6.1).使用 FluentValidation.AspNetCore(8.6.1 版)时收到以下错误。 this occurs when my edit view is saved.
保存我的编辑视图时会发生这种情况。 Very basic setup at the moment but i want to expand on the ActionValidator when it works...thanks
目前非常基本的设置,但我想在 ActionValidator 工作时扩展它......谢谢
Error cs0103 the name 'x' does not exist in the current context
错误 cs0103 当前上下文中不存在名称“x”
Code代码
Startup.cs -启动.cs -
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<ActionValidator>());
Validation class -验证类 -
public class ActionValidator : AbstractValidator<EditActionVM>
{
public ActionValidator()
{
RuleFor(x => x.ActionCompletionDate).NotEmpty();
}
}
What i have tried我试过的
Following the FluentValidation guide at - https://docs.fluentvalidation.net/en/latest/aspnet.html#getting-started遵循 FluentValidation 指南 - https://docs.fluentvalidation.net/en/latest/aspnet.html#getting-started
Changing startup to use the following code -更改启动以使用以下代码 -
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddFluentValidation();
services.AddTransient<IValidator<EditActionVM>, ActionValidator>();
Edit编辑
EditActionVM.cs - EditActionVM.cs -
public class EditActionVM
{
public int Id { get; set; }
[Display(Name = "Action Reference")]
public string ActionRef { get; set; }
[Display(Name = "Status")]
public Enums.Enums.Status Status { get; set; }
[Display(Name = "Created Date")]
public DateTime? CreatedDate { get; set; }
[Display(Name = "Action Completion Date")]
public DateTime? ActionCompletionDate { get; set; }
}
重新安装 FluentValidation 解决了我的问题......我的环境中可能有一些东西导致了这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.