Hi, in the docs here (https://docs.asp.net/en/latest/mvc/models/validation.html#id9) an example of implementing IClientModelValidator is given and in that example a method called MergeAttribute() is called. I have looked through the docs and searched around as best I can but I can't find a reference to this method anywhere.
Which assembly/package is it located in?
Many thanks, keep up the good work.
It's declared in ValidationAttributeAdapterOfTAttribute type which implements IClientModelValidator.
You don't really have to use this method, you can simply set it like this
C#
public override void AddValidation(ClientModelValidationContext context)
{
context.Attributes["data-val"] = "true";
context.Attributes["data-val-custom"] = "Error message";
}
Thanks @Muchiachio , I have done as you suggested for the time being but I was just wondering where it was so that I could use it if I wanted to. I tend to copy what Microsoft do in terms of their elements because I know they have spent more time working out the best/fastest way of developing these things.
The documentation displays snippets of a working sample, not all the pieces you need. While MVC uses a similar method internally, the better place to look is later in ClassicMovieAttribute. Comments on the doc page such as this one also contain the source.
I agree with the comments about the documentation being incomplete. It references a method called GetErrorMessage that is nowhere to be found in the sample code.
They have added the GetErrorMessage. Here it is:
private string GetErrorMessage()
{
return $"Classic movies must have a release year earlier than {_year}.";
}
Most helpful comment
The documentation displays snippets of a working sample, not all the pieces you need. While MVC uses a similar method internally, the better place to look is later in
ClassicMovieAttribute. Comments on the doc page such as this one also contain the source.