本文整理汇总了C#中System.Web.Mvc.ModelClientValidationRule类的典型用法代码示例。如果您正苦于以下问题:C# ModelClientValidationRule类的具体用法?C# ModelClientValidationRule怎么用?C# ModelClientValidationRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModelClientValidationRule类属于System.Web.Mvc命名空间,在下文中一共展示了ModelClientValidationRule类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule()
{
ErrorMessage = FormatErrorMessage(metadata.GetDisplayName()),
ValidationType = "validname",
};
var clientValidationRules = new List<string>
{
_onlyOneEntityValidator.GetClientValidationRules(metadata,context).First().ValidationType,
_cannotBeNotApplicable.GetClientValidationRules(metadata,context).First().ValidationType,
_cannotContainNumbers.GetClientValidationRules(metadata,context).First().ValidationType,
};
var regexPatterns = new List<string>
{
_onlyOneEntityValidator.Pattern,
_cannotBeNotApplicable.Pattern,
_cannotContainNumbers.Pattern,
};
var errorMessages = new List<string>
{
_onlyOneEntityValidator.FormatErrorMessage(metadata.GetDisplayName()),
_cannotBeNotApplicable.FormatErrorMessage(metadata.GetDisplayName()),
_cannotContainNumbers.FormatErrorMessage(metadata.GetDisplayName())
};
rule.ValidationParameters.Add("clientvalidationrules", clientValidationRules.Aggregate((i, j) => i + "," + j));
rule.ValidationParameters.Add("regexpatterns", regexPatterns.Aggregate((i, j) => i + "," + j));
rule.ValidationParameters.Add("errormessages", errorMessages.Aggregate((i, j) => i + "," + j));
yield return rule;
}
开发者ID:mrtony,项目名称:AspNet-MVC-Samples,代码行数:33,代码来源:ValidNameAttribute.cs
示例2: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
ModelClientValidationRule ccvAttribute = new ModelClientValidationRule();
ccvAttribute.ErrorMessage = this.ErrorMessage;
ccvAttribute.ValidationType = "ccv";
yield return ccvAttribute;
}
开发者ID:Brontsy,项目名称:Vintage-Rabbit,代码行数:7,代码来源:CCVAttribute.cs
示例3: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule()
{
ErrorMessage = FormatErrorMessage(metadata.GetDisplayName()),
ValidationType = "requiredifany",
};
var properties = new List<string>();
var values = new List<object>();
for (int i = 0; i < DependentProperties.Count(); i++)
{
string depProp = BuildDependentPropertyId(metadata, context as ViewContext, DependentProperties[i]);
// find the value on the control we depend on;
// if it's a bool, format it javascript style
// (the default is True or False!)
string targetValue = (TargetValues[i] ?? "").ToString();
if (TargetValues[i].GetType() == typeof(bool))
targetValue = targetValue.ToLower();
properties.Add(depProp);
values.Add(targetValue);
}
rule.ValidationParameters.Add("dependentproperties", String.Join("|", properties));
rule.ValidationParameters.Add("targetvalues", String.Join("|", values));
yield return rule;
}
开发者ID:Normmatt,项目名称:NzbDrone,代码行数:31,代码来源:RequiredIfAnyAttribute.cs
示例4: MessageOrDefault
protected string MessageOrDefault(ModelClientValidationRule rule, string propertyName)
{
// We don't want to display the default {validator.*} messages
if ((rule.ErrorMessage != null) && !rule.ErrorMessage.StartsWith("{validator."))
return rule.ErrorMessage;
switch (rule.ValidationType)
{
case "stringLength":
var maxLength = (int)rule.ValidationParameters["maximumLength"];
return
new StringLengthAttribute(maxLength).FormatErrorMessage(propertyName);
case "required":
return new RequiredAttribute().FormatErrorMessage(propertyName);
case "range":
var min = Convert.ToDouble(rule.ValidationParameters["minimum"]);
var max = Convert.ToDouble(rule.ValidationParameters["maximum"]);
return
new System.ComponentModel.DataAnnotations.RangeAttribute(min, max).FormatErrorMessage(propertyName);
case "regularExpression":
var pattern = (string)rule.ValidationParameters["pattern"];
return new RegularExpressionAttribute(pattern).FormatErrorMessage(propertyName);
default:
throw new NotSupportedException(
"Only stringLength, Required, Range and RegularExpression validators are supported for generic error messages. Add a custom error message or choose another validator type");
}
}
开发者ID:MJRichardson,项目名称:Sharp-Architecture,代码行数:27,代码来源:NHibernateValidatorClientProvider.cs
示例5: GetClientValidationRules
/// <summary>
/// When implemented in a class, returns client validation rules for that class.
/// </summary>
/// <param name="metadata">The model metadata.</param>
/// <param name="context">The controller context.</param>
/// <returns>
/// The client validation rules for this validator.
/// </returns>
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule { ErrorMessage = ErrorMessageString ?? "Field invalid. Field can only contain alphanumeric characters: 'a-z', 'A-Z', '0-9'.", ValidationType = clientValidationRule };
rule.ValidationParameters.Add("pattern", RootModuleConstants.AlphanumericExpression);
yield return rule;
}
开发者ID:vivekmalikymca,项目名称:BetterCMS,代码行数:15,代码来源:DisallowNonAlphanumericAttribute.cs
示例6: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule();
rule.ValidationType = "gangmember";
rule.ErrorMessage = "You must be in the gang";
yield return rule;
}
开发者ID:kevinrjones,项目名称:MVC20130916,代码行数:7,代码来源:GangMemberAttribute.cs
示例7: GetClientValidationRules
/// <summary>
/// When implemented in a class, returns client validation rules for that class.
/// </summary>
/// <param name="metadata">The model metadata.</param>
/// <param name="context">The controller context.</param>
/// <returns>
/// The client validation rules for this validator.
/// </returns>
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule { ErrorMessage = ErrorMessageString ?? "Field must not contain HTML.", ValidationType = clientValidationRule };
rule.ValidationParameters.Add("pattern", RootModuleConstants.HtmlRegularExpression);
yield return rule;
}
开发者ID:wezmag,项目名称:BetterCMS,代码行数:15,代码来源:DisallowHtmlAttribute.cs
示例8: GetClientValidationRules
/// <summary>
/// When implemented in a class, returns client validation rules for that class.
/// </summary>
/// <param name="metadata">The model metadata.</param>
/// <param name="context">The controller context.</param>
/// <returns>
/// The client validation rules for this validator.
/// </returns>
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule { ErrorMessage = ErrorMessageString ?? "The field must not contain any of the following characters: \" / \\ [ ] : ; | = , + * ? < > %", ValidationType = clientValidationRule };
rule.ValidationParameters.Add("pattern", RootModuleConstants.ActiveDirectoryNonCompliantExpression);
yield return rule;
}
开发者ID:wezmag,项目名称:BetterCMS,代码行数:15,代码来源:DisallowNonActiveDirectoryNameCompliantAttribute.cs
示例9: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule();
rule.ErrorMessage = "true";
rule.ValidationType = "dbisunique";
yield return rule;
}
开发者ID:naishan,项目名称:SDDB,代码行数:7,代码来源:DbDataAnnotations.cs
示例10: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule()
{
ErrorMessage = FormatErrorMessage(metadata.GetDisplayName()),
ValidationType = (_invertToRequiredIfNot ? "requiredifnot" : "requiredif"),
};
string depProp = BuildDependentPropertyId(metadata, context as ViewContext);
// find the value on the control we depend on;
// if it's a bool, format it JavaScript style
// (the default is True or False!)
StringBuilder sb = new StringBuilder();
foreach (var obj in this._targetValues)
{
string targetValue = (obj ?? string.Empty).ToString();
if (obj.GetType() == typeof(bool))
targetValue = targetValue.ToLower();
sb.AppendFormat("|{0}", targetValue);
}
rule.ValidationParameters.Add("dependentproperty", depProp);
rule.ValidationParameters.Add("targetvalue", sb.ToString().TrimStart('|'));
yield return rule;
}
开发者ID:StuartLeitch,项目名称:MvcFrameworkTest,代码行数:30,代码来源:RequiredIfAttribute.cs
示例11: SetModelValidationRule
protected override void SetModelValidationRule(ModelClientValidationRule rule)
{
base.SetModelValidationRule(rule);
switch (rule.ValidationType)
{
case "required":
this.AllowBlank = false;
this.BlankText = rule.ErrorMessage;
break;
case "range":
if (rule.ValidationParameters.ContainsKey("max"))
{
this.MaxSelections = (int)Convert.ChangeType(rule.ValidationParameters["max"], typeof(int));
this.MaxSelectionsText = rule.ErrorMessage;
}
if (rule.ValidationParameters.ContainsKey("min"))
{
this.MinSelections = (int)Convert.ChangeType(rule.ValidationParameters["min"], typeof(int));
this.MinSelectionsText = rule.ErrorMessage;
}
break;
}
}
开发者ID:shalves,项目名称:Ext.NET.Community,代码行数:25,代码来源:MultiSelectBase.cs
示例12: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule
{
ErrorMessage = string.Format(ErrorMessage, metadata.GetDisplayName()),
ValidationType = "requiredif",
};
var viewContext = (ViewContext)context;
var oldPrefix = viewContext.ViewData.TemplateInfo.HtmlFieldPrefix;
// only strip prefix when it exists
viewContext.ViewData.TemplateInfo.HtmlFieldPrefix = string.Empty;
var otherInputName = viewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(OtherProperty);
var thisPropertyName = ".{0}".FormatWith(metadata.PropertyName);
if (oldPrefix.EndsWith(thisPropertyName))
{
viewContext.ViewData.TemplateInfo.HtmlFieldPrefix = oldPrefix.Replace(thisPropertyName, string.Empty);
otherInputName = viewContext
.ViewData
.TemplateInfo
.GetFullHtmlFieldName(OtherProperty);
}
viewContext.ViewData.TemplateInfo.HtmlFieldPrefix = oldPrefix;
rule.ValidationParameters.Add("otherinputname", otherInputName);
rule.ValidationParameters.Add("comparisontype", ComparisonType);
rule.ValidationParameters.Add("othercomparisonvalue", OtherComparisonValue);
yield return rule;
}
开发者ID:saibalghosh,项目名称:UCosmic,代码行数:32,代码来源:RequiredIfClientAttribute.cs
示例13: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
string errorMessage = FormatErrorMessage("");
ModelClientValidationRule rule = new ModelClientValidationRule { ValidationType = "agerange", ErrorMessage = errorMessage };
rule.ValidationParameters.Add("minage", this.Minimum);
rule.ValidationParameters.Add("maxage", this.Maximum);
yield return rule;
}
开发者ID:xiaohong2015,项目名称:.NET,代码行数:8,代码来源:AgeRangeAttribute.cs
示例14: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule();
rule.ErrorMessage = FormatErrorMessage(metadata.DisplayName);
rule.ValidationType = "startsafter";
rule.ValidationParameters.Add("date", DateTime.Today.ToString(CultureInfo.InvariantCulture));
yield return rule;
}
开发者ID:TommyNewbie,项目名称:TimeManager,代码行数:8,代码来源:StartsAfterTodayAttribute.cs
示例15: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var existsRule = new ModelClientValidationRule { ValidationType = "existsin", ErrorMessage = FormatErrorMessage(metadata.DisplayName ?? metadata.PropertyName) };
existsRule.ValidationParameters["collection"] = Collection;
existsRule.ValidationParameters["value"] = Value;
existsRule.ValidationParameters["display"] = Display;
yield return existsRule;
}
开发者ID:SharePointSusan,项目名称:Research-Data-Manager,代码行数:8,代码来源:ExistsInAttribute.cs
示例16: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule();
rule.ErrorMessage = ErrorMessage;
rule.ValidationType = "requiredchecked";
yield return rule;
}
开发者ID:SharpSeeEr,项目名称:SharpNET.Utilities,代码行数:8,代码来源:RequiredChecked.cs
示例17: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
ModelClientValidationRule requiredIfNull = new ModelClientValidationRule();
requiredIfNull.ErrorMessage = this.ErrorMessage;
requiredIfNull.ValidationType = "requiredifpropertiesisnull";
requiredIfNull.ValidationParameters.Add("properties", string.Join(",", this.Properties));
yield return requiredIfNull;
}
开发者ID:Brontsy,项目名称:Castlerock,代码行数:8,代码来源:RequiredIfPropertiesIsNullAttribute.cs
示例18: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(
ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule
{ErrorMessage = FormatErrorMessage(metadata.GetDisplayName()), ValidationType = "greater"};
rule.ValidationParameters.Add("other", OtherPropertyName);
yield return rule;
}
开发者ID:feanz,项目名称:Example,代码行数:8,代码来源:GreaterThanDateAttribute.cs
示例19: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule();
rule.ErrorMessage = this.FormatErrorMessage(metadata.PropertyName);
rule.ValidationType = "min";
rule.ValidationParameters.Add("value",minValue);
yield return rule;
}
开发者ID:snahider,项目名称:TiendaVirtual,代码行数:8,代码来源:MinAttribute.cs
示例20: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context) {
var rule = new ModelClientValidationRule {
ValidationType = "accept",
ErrorMessage = FormatErrorMessage(metadata.GetDisplayName())
};
rule.ValidationParameters["exts"] = ExtensionsNormalized;
yield return rule;
}
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:8,代码来源:FileExtensionsAttribute.cs
注:本文中的System.Web.Mvc.ModelClientValidationRule类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论