Validation type names in unobtrusive client validation rules must consist

1k views Asked by At

I am strugling with the following problem on my MVC 5 site.

Validation type names in unobtrusive client validation rules must consist of only lowercase letters. Invalid name: "requiredif4", client rule type: RequiredIfValidationRule

Does this error means I can only use characters a-z in the name and nothing else.

This error doesn't occur always. The page renders fine for a while and then suddenly this error starts occuring. When I then recycle my application pool, the error goes away for a few hours.

Any ideas on what could be the problem ?

1

There are 1 answers

0
Jaco B On BEST ANSWER

I finally managed to solve this problem.

Below is the full solution. In short, if you have a ValidationRule that will be visited multiple times (in my case hundreds of times) you need to make sure the name stays unique for as long as the IIS session is active. In my case that is 24 hours.

The below code generate a unique name for the ValidationRule on the client side.

The code to fix the problem looks as follows:

const string Chars = "abcdefghijklmnopqrstuvwxyz";

var c = "";
if (count > 0)
{
    var p = 0;
    while (count / Math.Pow(Chars.Length, p) > Chars.Length)
        p++;

    while (p > 0)
    {
        var i = (int)(count / Math.Pow(Chars.Length, p));
        c += Chars[Math.Max(i, 1) - 1];
        count = count - (int)(i * Math.Pow(Chars.Length, p));
        p--;
    }
    var ip = Math.Max(Math.Min((count) % Chars.Length, Chars.Length - 1), 0);
    c += Chars[ip];
}

Regards