Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4082064
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:08:28+00:00 2026-05-20T18:08:28+00:00

i want to override the default asp.net-mvc validation when posting a form so i

  • 0

i want to override the default asp.net-mvc validation when posting a form so i tried using fluent.validation

i created a validator class (ProjectValidator)

public class ProjectValidator : AbstractValidator<Project>
{
    public ProjectValidator()
    {
        RuleFor(h => h.Application).NotNull().WithName("Application");
        RuleFor(h => h.FundingType).NotNull().WithName("Funding Type");
        RuleFor(h => h.Description).NotEmpty().WithName("Description");
        RuleFor(h => h.Name).NotEmpty().WithName("Project Name");
    }
}

i put an attribute on my Data Transfer Object class

[Validator(typeof(ProjectValidator))]
  public class ProjectViewModel
  {
      ...
  }

and i put this in application_start();

 DataAnnotationsModelValidatorProvider
            .AddImplicitRequiredAttributeForValueTypes = false;

 ModelValidatorProviders.Providers.Add(
            new FluentValidationModelValidatorProvider(new AttributedValidatorFactory()));

but when i post a form that uses this object, i get the following error:

Method not found: ‘System.Collections.Generic.IEnumerable`1 FluentValidation.IValidatorDescriptor.GetValidatorsForMember(System.String)’.

any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:08:29+00:00Added an answer on May 20, 2026 at 6:08 pm

    It could be a problem related to the assembly versions you are using. Here are the steps that work for me with the latest version of FluentValidation.NET and ASP.NET MVC 3:

    1. Create a new ASP.NET MVC 3 project using the default Visual Studio template.
    2. Install the FluentValidation.MVC3 NuGet package.
    3. Add the view model and its corresponding validator (notice that in your case you have the validator for type Project – AbstractValidator<Project> whereas your view model is called ProjectViewModel which is inconsistent. The validator must be associated to the view model):

      public class ProjectValidator : AbstractValidator<ProjectViewModel>
      {
          public ProjectValidator()
          {
              RuleFor(h => h.Application).NotNull().WithName("Application");
              RuleFor(h => h.FundingType).NotNull().WithName("Funding Type");
              RuleFor(h => h.Description).NotEmpty().WithName("Description");
              RuleFor(h => h.Name).NotEmpty().WithName("Project Name");
          }
      }
      
      [Validator(typeof(ProjectValidator))]
      public class ProjectViewModel
      {
          public string Application { get; set; }
          public string FundingType { get; set; }
          public string Description { get; set; }
          public string Name { get; set; }
      }
      
    4. In Application_Start register the validator:

      protected void Application_Start()
      {
          AreaRegistration.RegisterAllAreas();
      
          RegisterGlobalFilters(GlobalFilters.Filters);
          RegisterRoutes(RouteTable.Routes);
      
          DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
          ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(new AttributedValidatorFactory()));
      }
      
    5. Define a controller:

      public class HomeController : Controller
      {
          public ActionResult Index()
          {
              return View(new ProjectViewModel());
          }
      
          [HttpPost]
          public ActionResult Index(ProjectViewModel model)
          {
              return View(model);
          }
      }
      
    6. And a view:

      @model Appame.Models.ProjectViewModel
      
      @using (Html.BeginForm())
      {
          <div>
              @Html.LabelFor(x => x.Application)
              @Html.EditorFor(x => x.Application)
              @Html.ValidationMessageFor(x => x.Application)
          </div>
          <div>
              @Html.LabelFor(x => x.FundingType)
              @Html.EditorFor(x => x.FundingType)
              @Html.ValidationMessageFor(x => x.FundingType)
          </div>
          <div>
              @Html.LabelFor(x => x.Description)
              @Html.EditorFor(x => x.Description)
              @Html.ValidationMessageFor(x => x.Description)
          </div>
          <div>
              @Html.LabelFor(x => x.Name)
              @Html.EditorFor(x => x.Name)
              @Html.ValidationMessageFor(x => x.Name)
          </div>
      
          <input type="submit" value="OK" />
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ASP.NET MVC2 with MvcContrib.FluentHtml to do form binding. I want to
I want to set up a ASP.NET MVC route that looks like: routes.MapRoute( Default,
I want to override a string from a System.ComponentModel.DataAnnotations for an ASP.NET project. Do
First some brief background: I have an existing ASP.NET MVC 1 application using Entity
I want to disable or override the default help function of browsers. I tried
I'm using ASP.NET MVC with IIS 7.0. I've got 404 errors hooked up fine
I'm building an api using ASP.NET MVC 3. When a controller action is not
I'm using sfGuard plugin for Doctrine. I want to override the default error message
just wondering if there is something built into asp.net mvc where I can override
I'm using restful routing module for asp.net mvc and very happy with it. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.