当前位置: 首页>>代码示例>>C#>>正文


C# ModelMetadata.GetDisplayName方法代码示例

本文整理汇总了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;
        }
开发者ID:mrtony,项目名称:AspNet-MVC-Samples,代码行数:33,代码来源:ValidNameAttribute.cs

示例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;
        }
开发者ID:StuartLeitch,项目名称:MvcFrameworkTest,代码行数:30,代码来源:RequiredIfAttribute.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: 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;
 }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:7,代码来源:ModelBinderConfig.cs

示例5: GetClientValidationRules

 public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
 {
     yield return new ModelClientValidationRule {
         ValidationType = "email",
         ErrorMessage = FormatErrorMessage(metadata.GetDisplayName())
     };
 }
开发者ID:ogazitt,项目名称:TaskStore,代码行数:7,代码来源:EmailAddressAttribute.cs

示例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;
        }
开发者ID:saibalghosh,项目名称:UCosmic,代码行数:32,代码来源:RequiredIfClientAttribute.cs

示例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;
        }
开发者ID:avannini,项目名称:uisp-mobile,代码行数:35,代码来源:LocalizedModelValidatorProvider.cs

示例8: GetClientValidationRules

 public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
 {
     return new[]
                {
                    new ModelClientValidationRangeDateRule(FormatErrorMessage(metadata.GetDisplayName()), _minDate, _maxDate)
                };
 }
开发者ID:fboja,项目名称:FlightJournal,代码行数:7,代码来源:DateRangeAttribute.cs

示例9: GetClientValidationRules

        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            var name = metadata.GetDisplayName();
            var message = FormatErrorMessage(name);

            yield return new TodayOrLaterClientValidationRule(message);
        }
开发者ID:davidpadbury,项目名称:aspmvc-jquery-win,代码行数:7,代码来源:TodayOrLaterAttribute.cs

示例10: GetClientValidationRules

 public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
 {
     return new[]
                {
                    new ModelClientValidationExcludeValuesRule(FormatErrorMessage(metadata.GetDisplayName()), this.Values)
                };
 }
开发者ID:hellangle,项目名称:NewCenturyLogistic,代码行数:7,代码来源:ExcludeValuesAttribute.cs

示例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;
 }
开发者ID:naishan,项目名称:SDDB,代码行数:7,代码来源:DbDataAnnotations.cs

示例12: GetClientValidationRules

 public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
 {
     return new[]
                         {
                             new ModelClientValidationStringLengthRule(FormatErrorMessage(metadata.GetDisplayName()), this.minCharacters, int.MaxValue)
                         };
 }
开发者ID:antonsamarsky,项目名称:e-commerce,代码行数:7,代码来源:ValidatePasswordLengthAttribute.cs

示例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);
        }
开发者ID:carlospeix,项目名称:ConfUi,代码行数:31,代码来源:MetadataProviderTest.cs

示例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));
                }
            }
        }
开发者ID:emayk,项目名称:Ext.NET.Pro,代码行数:35,代码来源:Field.cs

示例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;
 }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:8,代码来源:FileExtensionsAttribute.cs


注:本文中的ModelMetadata.GetDisplayName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。