本文整理汇总了C#中HtmlTags.HtmlTag.Data方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlTag.Data方法的具体用法?C# HtmlTag.Data怎么用?C# HtmlTag.Data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlTags.HtmlTag
的用法示例。
在下文中一共展示了HtmlTag.Data方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRegexData
public void AddRegexData(IEnumerable<ValidationAttribute> propertyValidators, HtmlTag htmlTag, RequestData request)
{
var regex = propertyValidators.OfType<RegularExpressionAttribute>().FirstOrDefault();
if (regex != null)
{
var msg = regex.ErrorMessage ?? string.Format("The field '{0}' did not match the regular expression '{1}'", request.Accessor.InnerProperty.Name, regex.Pattern);
if (_msUnobtrusive)
htmlTag.Data("val", true).Data("val-regex", msg).Data("val-regex-pattern", regex.Pattern);
else
htmlTag.Data("rule-regex", regex.Pattern).Data("msg-regex", msg);
}
}
示例2: Run
/// <summary>
/// Run the specified validator, tag and formattedMessage.
/// </summary>
/// <param name="validator">A validator.</param>
/// <param name="tag">A tag.</param>
/// <param name="formattedMessage">Formatted message.</param>
public void Run(FluentValidation.Validators.IPropertyValidator validator, HtmlTag tag, string formattedMessage)
{
if (validator is CpfValidator)
{
tag.Data("val-cpf", formattedMessage);
}
else if (validator is ValidDate)
{
tag.Data("val-dateBR", formattedMessage);
}
else if (validator is ValidNomeConjuge)
{
tag.Data("val-nomeConjuge", formattedMessage);
}
}
示例3: Modify
public virtual void Modify(HtmlTag form)
{
if (!_modify) return;
form.Data("validation-mode", _value.ToLower());
form.AddClass("validated-form");
}
示例4: AddEqualToDataAttr
public void AddEqualToDataAttr(IEnumerable<ValidationAttribute> propertyValidators, HtmlTag htmlTag, RequestData request)
{
var equal = propertyValidators.OfType<CompareAttribute>().FirstOrDefault();
if (equal != null)
{
var formatErrorMessage = equal.FormatErrorMessage(request.Accessor.Name);
if (_msUnobtrusive)
{
htmlTag.Data("val", true);
htmlTag.Data("val-equalto", formatErrorMessage);
if (request.Accessor.PropertyNames.Length > 1)
{
htmlTag.Data("val-equalto-other", request.Id.Replace("_" + request.Accessor.Name, "") + "_" + equal.OtherProperty);
}
else
{
htmlTag.Data("val-equalto-other", "*." + equal.OtherProperty);
}
}
else
{
htmlTag.Data("msg-equalto", formatErrorMessage);
if (request.Accessor.PropertyNames.Length > 1)
htmlTag.Data("rule-equalto", "#" + request.Id.Replace("_" + request.Accessor.Name, "") + "_" + equal.OtherProperty);
else
htmlTag.Data("rule-equalto", "#" + equal.OtherProperty);
}
}
}
示例5: AddEqualToDataAttr
public void AddEqualToDataAttr(IEnumerable<PropertyValidatorResult> propertyValidators, HtmlTag htmlTag, RequestData request)
{
var result = propertyValidators.FirstOrDefault(x => x.PropertyValidator is EqualValidator);
if (result != null)
{
var equal = result.PropertyValidator.As<EqualValidator>();
MessageFormatter formatter = new MessageFormatter()
.AppendPropertyName(result.DisplayName)
.AppendArgument("ComparisonValue", equal.ValueToCompare);
string message = formatter.BuildMessage(equal.ErrorMessageSource.GetString());
if (_msUnobtrusive)
{
htmlTag.Data("val", true);
htmlTag.Data("val-equalto", message);
if (request.Accessor.PropertyNames.Length > 1)
htmlTag.Data("val-equalto-other", request.Id.Replace("_" + request.Accessor.Name, "") + "_" + equal.MemberToCompare.Name);
else
htmlTag.Data("val-equalto-other", "*." + equal.MemberToCompare.Name);
}
else
{
htmlTag.Data("msg-equalto", message);
if (request.Accessor.PropertyNames.Length > 1)
htmlTag.Data("rule-equalto", "#" + request.Id.Replace("_" + request.Accessor.Name, "") + "_" + equal.MemberToCompare.Name);
else
htmlTag.Data("rule-equalto", "#" + equal.MemberToCompare.Name);
}
}
}
示例6: AddCreditCardClass
public void AddCreditCardClass(IEnumerable<PropertyValidatorResult> propertyValidators, HtmlTag htmlTag, RequestData requestData)
{
var lengthValidator = propertyValidators.Select(x => x.PropertyValidator).OfType<CreditCardValidator>().FirstOrDefault();
if (lengthValidator != null)
{
if (requestData.ViewContext.UnobtrusiveJavaScriptEnabled)
{
if (!_msUnobtrusive)
{
htmlTag.Data("rule-creditcard", true);
}
}
else
{
htmlTag.AddClass("creditcard");
}
}
}
示例7: AddRequiredClass
public void AddRequiredClass(IEnumerable<ValidationAttribute> propertyValidators, HtmlTag htmlTag, RequestData request)
{
var required = propertyValidators.OfType<RequiredAttribute>().FirstOrDefault();
if (required != null)
{
if (request.ViewContext.UnobtrusiveJavaScriptEnabled)
{
var msg = required.ErrorMessage ?? string.Format("The field '{0}' is required", request.Accessor.InnerProperty.Name);
if (_msUnobtrusive)
htmlTag.Data("val", true).Data("val-required", msg);
else
htmlTag.Data("rule-required", true).Data("msg-required", msg);
}
else
htmlTag.AddClass("required");
}
}
示例8: AddEmailData
public void AddEmailData(IEnumerable<PropertyValidatorResult> propertyValidators, HtmlTag htmlTag, RequestData requestData)
{
var result = propertyValidators.FirstOrDefault(x => x.PropertyValidator is EmailValidator);
if (result != null)
{
if (requestData.ViewContext.UnobtrusiveJavaScriptEnabled)
{
var msg = GetMessage(requestData, result) ?? string.Format("The value is not a valid email address");
if (_msUnobtrusive)
htmlTag.Data("val", true).Data("val-email", msg);
else
htmlTag.Data("rule-email", true).Data("msg-email", msg);
}
else
htmlTag.AddClass("email");
}
}
示例9: AddRequiredClass
public void AddRequiredClass(IEnumerable<PropertyValidatorResult> propertyValidators, HtmlTag htmlTag, RequestData requestData)
{
var result = propertyValidators.FirstOrDefault(x => x.PropertyValidator is NotEmptyValidator
|| x.PropertyValidator is NotNullValidator);
if (result != null)
{
if (requestData.ViewContext.UnobtrusiveJavaScriptEnabled)
{
if (_msUnobtrusive)
htmlTag.Data("val", true).Data("val-required", GetMessage(requestData, result) ?? string.Empty);
else
htmlTag.Data("rule-required", true).Data("msg-required", GetMessage(requestData, result) ?? string.Empty);
}
else
htmlTag.AddClass("required");
}
}
示例10: AddRegexData
public void AddRegexData(IEnumerable<PropertyValidatorResult> propertyValidators, HtmlTag htmlTag, RequestData requestData)
{
var result = propertyValidators.FirstOrDefault(x => x.PropertyValidator is RegularExpressionValidator);
if (result != null && requestData.ViewContext.UnobtrusiveJavaScriptEnabled)
{
var regex = result.PropertyValidator.As<RegularExpressionValidator>();
var msg = GetMessage(requestData, result) ?? string.Format("The value did not match the regular expression '{0}'", regex.Expression);
if (_msUnobtrusive)
htmlTag.Data("val", true).Data("val-regex", msg).Data("val-regex-pattern", regex.Expression);
else
htmlTag.Data("rule-regex", regex.Expression).Data("msg-regex", msg);
}
}