简体   繁体   English

FluentValidation“错误 cs0103 当前上下文中不存在名称‘x’”.asp.net 核心 2.1

[英]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.

相关问题 ASP.NET 核心 Web API - 错误 CS0103 当前上下文中不存在名称“FetchToken” - ASP.NET Core Web API - Error CS0103 The name 'FetchToken' does not exist in the current context ASP.NET 内核 Web API - 如何解决错误 CS0103 名称“分数”在当前上下文中不存在 - ASP.NET Core Web API - How to resolve Error CS0103 The name 'score' does not exist in the current context 无效的Intellisense错误CS0103 ASP.NET网站“该名称在当前上下文中不存在” - Invalid Intellisense error CS0103 ASP.NET Web Site “The name does not exist in the current context” 错误 CS0103:当前上下文中不存在名称“x” - error CS0103: The name 'x' does not exist in the current context 错误 CS0103:当前上下文中不存在名称“_context” - Error CS0103: The name '_context' does not exist in the current context 错误 CS0103:当前上下文中不存在名称“currentScreen”(CS0103) - Error CS0103: The name 'currentScreen' does not exist in the current context (CS0103) 错误CS0103:名称“ TimeSpan”在当前上下文(CS0103)(testingProgram)中不存在? - Error CS0103: The name 'TimeSpan' does not exist in the current context (CS0103) (testingProgram)? 错误cs0103名称&#39;IEnumerator&#39;在当前上下文中不存在 - error cs0103 The Name 'IEnumerator' does not exist in the current context 错误CS0103:名称“ HttpUtility”在当前上下文中不存在 - error CS0103: The name `HttpUtility' does not exist in the current context "错误 CS0103:当前上下文中不存在名称“AssetPreview”" - error CS0103: The name 'AssetPreview' does not exist in the current context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM