本文整理汇总了C#中ModelMetadata.GetDisplayName方法的典型用法代码示例。如果您正苦于以下问题:C# ModelMetadata.GetDisplayName方法的具体用法?C# ModelMetadata.GetDisplayName怎么用?C# ModelMetadata.GetDisplayName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelMetadata
的用法示例。
在下文中一共展示了ModelMetadata.GetDisplayName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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;
}
示例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;
}
示例4: GetResourceCommon
private static string GetResourceCommon(ControllerContext controllerContext, ModelMetadata modelMetadata, object incomingValue, Func<ControllerContext, string> resourceAccessor)
{
string displayName = modelMetadata.GetDisplayName();
string errorMessageTemplate = resourceAccessor(controllerContext);
string errorMessage = String.Format(CultureInfo.CurrentCulture, errorMessageTemplate, incomingValue, displayName);
return errorMessage;
}
示例5: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
yield return new ModelClientValidationRule {
ValidationType = "email",
ErrorMessage = FormatErrorMessage(metadata.GetDisplayName())
};
}
示例6: 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;
}
示例7: GetValidators
protected override IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context,
IEnumerable<Attribute> attributes)
{
var items = attributes.ToList();
//se non c'è IgnoreValidationAttribute si mette required sulle properties non nullabili
if (AddImplicitRequiredAttributeForValueTypes && metadata.IsRequired &&
metadata.ContainerType!= null && !metadata.ContainerType.GetCustomAttributes(typeof(IgnoreValidationAttribute), true).Any() &&
!items.Any(a => a is RequiredAttribute || a is IgnoreValidationAttribute))
items.Add(new RequiredAttribute());
var validators = new List<ModelValidator>();
foreach (var attr in items.OfType<ValidationAttribute>())
{
string formattedError;
try
{
lock (attr)
{
attr.ErrorMessage = GetText(attr.ErrorMessage, attr, metadata);
formattedError = attr.FormatErrorMessage(metadata.GetDisplayName());
attr.ErrorMessage = null;
// Questo serve per evitare che i valori standard vengano scritti sul DB
}
}
catch (Exception err)
{
formattedError = err.Message;
}
validators.Add(new MyValidator(attr, attr.ErrorMessage, metadata, context,
_adapterFactory.Create(attr, formattedError)));
}
return validators;
}
示例8: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
return new[]
{
new ModelClientValidationRangeDateRule(FormatErrorMessage(metadata.GetDisplayName()), _minDate, _maxDate)
};
}
示例9: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var name = metadata.GetDisplayName();
var message = FormatErrorMessage(name);
yield return new TodayOrLaterClientValidationRule(message);
}
示例10: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
return new[]
{
new ModelClientValidationExcludeValuesRule(FormatErrorMessage(metadata.GetDisplayName()), this.Values)
};
}
示例11: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule();
rule.ErrorMessage = FormatErrorMessage(metadata.GetDisplayName());
rule.ValidationType = "dbisbool";
yield return rule;
}
示例12: GetClientValidationRules
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
return new[]
{
new ModelClientValidationStringLengthRule(FormatErrorMessage(metadata.GetDisplayName()), this.minCharacters, int.MaxValue)
};
}
示例13: CompareMetadata
private static void CompareMetadata(ModelMetadata metadataDamp, ModelMetadata metadataGmp)
{
Assert.AreEqual(metadataDamp.AdditionalValues.Count, metadataGmp.AdditionalValues.Count);
Assert.IsNull(metadataDamp.ContainerType); Assert.IsNull(metadataGmp.ContainerType);
Assert.AreEqual(metadataDamp.ConvertEmptyStringToNull, metadataGmp.ConvertEmptyStringToNull);
Assert.IsNull(metadataDamp.DataTypeName); Assert.IsNull(metadataGmp.DataTypeName);
Assert.IsNull(metadataDamp.Description); Assert.IsNull(metadataGmp.Description);
Assert.IsNull(metadataDamp.DisplayFormatString); Assert.IsNull(metadataGmp.DisplayFormatString);
Assert.IsNull(metadataDamp.DisplayName); Assert.IsNull(metadataGmp.DisplayName);
Assert.IsNull(metadataDamp.EditFormatString); Assert.IsNull(metadataGmp.EditFormatString);
Assert.AreEqual(metadataDamp.GetDisplayName(), metadataGmp.GetDisplayName());
Assert.AreEqual(metadataDamp.HideSurroundingHtml, metadataGmp.HideSurroundingHtml);
Assert.AreEqual(metadataDamp.IsComplexType, metadataGmp.IsComplexType);
Assert.AreEqual(metadataDamp.IsNullableValueType, metadataGmp.IsNullableValueType);
Assert.AreEqual(metadataDamp.IsReadOnly, metadataGmp.IsReadOnly);
Assert.AreEqual(metadataDamp.IsRequired, metadataGmp.IsRequired);
Assert.IsNotNull(metadataDamp.Model); Assert.IsNotNull(metadataGmp.Model);
Assert.AreEqual(metadataDamp.ModelType, metadataGmp.ModelType);
Assert.IsNull(metadataDamp.NullDisplayText); Assert.IsNull(metadataGmp.NullDisplayText);
Assert.AreEqual(metadataDamp.Order, metadataGmp.Order);
Assert.IsNull(metadataDamp.PropertyName); Assert.IsNull(metadataGmp.PropertyName);
Assert.AreEqual(metadataDamp.RequestValidationEnabled, metadataGmp.RequestValidationEnabled);
Assert.IsNull(metadataDamp.ShortDisplayName); Assert.IsNull(metadataGmp.ShortDisplayName);
Assert.AreEqual(metadataDamp.ShowForDisplay, metadataGmp.ShowForDisplay);
Assert.AreEqual(metadataDamp.ShowForEdit, metadataGmp.ShowForEdit);
Assert.AreEqual(metadataDamp.SimpleDisplayText, metadataGmp.SimpleDisplayText);
Assert.IsNull(metadataDamp.TemplateHint); Assert.IsNull(metadataGmp.TemplateHint);
Assert.IsNull(metadataDamp.Watermark); Assert.IsNull(metadataGmp.Watermark);
ComparePropertyMetadata(metadataDamp.Properties, metadataGmp.Properties);
}
示例14: OnMetadataProcess
protected override void OnMetadataProcess(ModelMetadata meta, string name, ViewDataDictionary viewData, ControllerContext context)
{
base.OnMetadataProcess(meta, name, viewData, context);
if (name.IsEmpty())
{
throw new Exception("Name from ControlFor is empty");
}
this.Name = name;
if (meta.IsReadOnly)
{
this.ReadOnly = true;
}
if (this.FieldLabel.IsEmpty())
{
this.FieldLabel = meta.GetDisplayName();
}
if (this.Note.IsEmpty() && meta.Description.IsNotEmpty())
{
this.Note = meta.Description;
}
ModelState modelState;
if (viewData.ModelState.TryGetValue(name, out modelState))
{
if (modelState.Errors.Count > 0)
{
this.CustomConfig.Add(new ConfigItem("activeError", JSON.Serialize(modelState.Errors.Select(e => e.ErrorMessage)), ParameterMode.Raw));
}
}
}
示例15: 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;
}