Property Value not Getting With Localizemessage and WithMessage

Jun 24, 2013 at 3:19 PM
Hi ,


I have a model class Customer in which have the CustomerIndex and CustomerName Property.

I need to Show the message when CustomerName is null.
Message is "Please provide the Name of Customer 1." Then 1 is the value of CustomerIndex.


RuleFor(x => x.CustomerName).NotNull().WithMessage("Please provide the Name of Customer", x => x.CustomerIndex))


But when i am executing this code I have found the message "Please provide the Name of Customer true"

I have found the true value in place of 1.

So can u please suggest me what is the issue.
Coordinator
Jun 25, 2013 at 2:53 PM
If you want put other properties inside the error message you must use a format string instead of a simple string error message:

RuleFor(x => x.CustomerName).NotNull().WithMessage("Please provide the Name of Customer {0}", x => x.CustomerIndex))