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

  • Home
  • SEARCH
  • 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 6792171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:56:11+00:00 2026-05-26T17:56:11+00:00

I have the following classes, they are bit simplified for example. class LineInfo {

  • 0

I have the following classes, they are bit simplified for example.

class LineInfo
{   
    Id,
    LineNumber,
    SubAccountNumer,
    MobileNumber
}

class SuspendLinesVM{
    public List<LineInfo> Lines{ get;set; }
}

I receive SuspendLinesVM in my action and all Lines are created dynamicaly from client. Each element that belongs to concrete LineInfo in form has name with template ‘lineid{Id}_ElementName‘. So they comes to me in form like:

lineid0001_LineNumber

lineid0001_SubAccountNumer

lineid0001_MobileNumber

lineid0021_LineNumber

lineid0021_SubAccountNumer

lineid0021_MobileNumber

When some error occures while validation, I need a way to set the failed property as it came in request to highlight invalid fields in the view.

I left questions where I got confused.

 public class LineInfoValidator: AbstractValidator<LineInfo>
    {
        public LineInfoValidator()
        {
            RuleFor(m => m.LineNumber)
                .NotEmpty().WithMessage("Line # is required").OverridePropertyName( ??? ) 
                .InclusiveBetween(1, 9999).WithMessage("Line # must be in range [1, 9999]").OverridePropertyName( ??? )
...

I need a way to do something like *(instance, propertyName) => return string.format(‘lineid_{0}_{1}’, instance.Id, propertyName)*.

Any ideas ?

  • 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-26T17:56:12+00:00Added an answer on May 26, 2026 at 5:56 pm

    Resolved with ‘WithState’ method. Thanks to Jeremy! His solution is here http://fluentvalidation.codeplex.com/discussions/278892

    JeremyS
    Nov 10, 2011 at 5:16 PM

    Unfortunately this isn’t something that is supported.

    Property names are resolved only once when the validator is instantiated, as opposed to error messages which are generated when the validator is executed. In this case, you need to inspect the instance being validated to generate the property name, which isn’t actually possible – the closest you’d be able to get is to use the WithState method to associate some custom state with the failure:

    RuleFor(x => x.LineNumber)
        .NotEmpty()
        .WithState(instance => string.Format("lineid_{0}_LineNumber", instance.Id));
    

    Once you invoke the validator and get back the ValidationResult, you can retrieve this from the CustomState property on the ValidationFailure.

    Jeremy

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

Sidebar

Related Questions

I have the following classes [XmlRoot] public class AList { public List<B> ListOfBs {get;
I have following classes. class A { public: void fun(); } class B: public
I have the following classes public interface InterfaceBase { } public class ImplementA:InterfaceBase {
I have the following classes: public class Person { public String FirstName { set;
I have the following classes defined to do validation: public class DefValidator : IValidate<IDef>
I have the following classes in my Model: public abstract class Entity : IEntity
I have the following classes: class Person { public string Name { get; set;
I have the following classes: public class Foo { [Import] public IFirstInterface firstImport; [Import]
Let's say I have the following two classes: public class TestResults { public string
I have the following classes: Ingredients, Recipe and RecipeContent... class Ingredient(models.Model): name = models.CharField(max_length=30,

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.