I basically had the same problem, and I was able to solve it with the following code snippet: (As said here: ASP.NET MVC - "Validation type names must be unique." )
using System; using System.Web.Mvc; And ValidationRule:
public class RequiredIfValidationRule: ModelClientValidationRule {private const string Chars = "abcdefghijklmnopqrstuvwxyz";
public RequiredIfValidationRule(string errorMessage, string reqVal, string otherProperties, string otherValues, int count) { 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]; } ErrorMessage = errorMessage;
}
Hope this helps.
source share