不显眼的客户端验证规则中的验证类型名称必须包含

Validation type names in unobtrusive client validation rules must consist

我在我的 MVC 5 站点上遇到以下问题。

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

这个错误是否意味着我只能在名称中使用字符 a-z 而不能使用其他字符。

这个错误并不总是发生。该页面可以正常显示一段时间,然后突然开始出现此错误。当我随后回收我的应用程序池时,错误消失了几个小时。

对可能出现的问题有什么想法吗?

我终于解决了这个问题。

下面是完整的解决方案。简而言之,如果您有一个将被访问多次(在我的例子中是数百次)的 ValidationRule,您需要确保该名称在 IIS 会话处于活动状态时保持唯一。在我的例子中是 24 小时。

下面的代码在客户端为 ValidationRule 生成一个唯一的名称。

修复问题的代码如下所示:

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];
}

此致