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 7745785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:06:39+00:00 2026-06-01T10:06:39+00:00

I debugged that all and noticed, that validator constructor is called (and not one

  • 0

I debugged that all and noticed, that validator constructor is called (and not one time, that strangely). That is my IoC factory works properly.
Custom validation with service calls (rules with rulesets) works normally (I debugged – calls made). But standard validation rules (NotEmpty, Length, Matches and Must for Categories property) don’t work – no validation errors in ModelState object.

That all works early, I don’t change any of code posted here. No global model binders were changed/added. I have no ideas.

Code for model with not non-working validation:

My post action:

        [HttpPost]
        public ActionResult CreateTest([CustomizeValidator(RuleSet = "New")] Test model)
        {
            if (ModelState.IsValid)
            {
                var testId = testService.CreateTest(model);
                return RedirectToAction("Test", new { testId });
            }

            PrepareTestEdit(true);
            return View("EditTest");
        }

My model:

[Validator(typeof(TestValidator))]
public class Test
{
    public Test()
    {
        Categories = new List<string>();
    }

    public int Id { get; set; }

    public string Title { get; set; }

    public string Description { get; set; }

    public string UrlName { get; set; }

    public List<string> Categories { get; set; }
}

Validator:

public class TestValidator : AbstractValidator<Test>
{
    public TestValidator(ITestService testService)
    {
        RuleSet("Edit", () =>
            {
                RuleFor(x => x.Title).
                    Must((model, title) => testService.ValidateTitle(title, model.Id)).WithMessage("1");
                RuleFor(x => x.UrlName).
                    Must((model, urlName) => testService.ValidateUrlName(urlName, model.Id)).WithMessage("2");
            });

        RuleSet("New", () =>
        {
            RuleFor(x => x.Title).
                Must(title => testService.ValidateTitle(title)).WithMessage("3");
            RuleFor(x => x.UrlName).
                Must(urlName => testService.ValidateUrlName(urlName)).WithMessage("4");
        });

        RuleFor(x => x.Title).
            NotEmpty().WithMessage("5").
            Length(1, 100).WithMessage("6");
        RuleFor(x => x.UrlName).
            NotEmpty().WithMessage("7").
            Length(1, 100).WithMessage("8").
            Matches("^[-_a-zA-Z0-9]*$").WithMessage("9");
        RuleFor(x => x.Description).
            NotEmpty().WithMessage("10");
        RuleFor(x => x.Categories).
            Must(categories => categories != null && categories.Any()).WithMessage("11");
    }
}
  • 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-06-01T10:06:40+00:00Added an answer on June 1, 2026 at 10:06 am

    Fluent validation documentation

    RuleSets allow you to group validation rules together which can be executed together as a group whilst ignoring other rules

    I placed all common rules to separate private method and call it for both rulesets in anonymous function body.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 15 BackgroundWorers that are running all the time, each one of them
I have successfully debugged my own memory leak problems. However, I have noticed some
While surfing facebook and using the Firebug network debugger I noticed that facebook's AJAX
I have an app that works fine in iOS 4, but there is a
I've recently noticed that after my projects grow a certain size I end up
I have a WPF application that has just one button. When the button is
I'm having a hard time with a do-while loop, that is supposed to stop
I've a very simple function that should read a txt file and return all
I have a Panel that I'm setting visible=true explicitly. The debugger passes over that
My Visual Studio 2008 debugger is showing integers as hexadecimals, how to correct that?

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.