Example #1
0
        protected virtual string GenerateValue(string expression, object value, string format, bool useViewData)
        {
            var fullName       = NameAndIdProvider.GetFullHtmlFieldName(ViewContext, expression);
            var attemptedValue =
                (string)DefaultHtmlGenerator.GetModelStateValue(ViewContext, fullName, typeof(string));

            string resolvedValue;

            if (attemptedValue != null)
            {
                // case 1: if ModelState has a value then it's already formatted so ignore format string
                resolvedValue = attemptedValue;
            }
            else if (useViewData)
            {
                // case 2: format the value from ViewData
                resolvedValue = DefaultHtmlGenerator.EvalString(ViewContext, expression, format);
            }
            else
            {
                // case 3: format the explicit value from ModelMetadata
                resolvedValue = FormatValue(value, format);
            }

            return(resolvedValue);
        }
Example #2
0
        /// <inheritdoc />
        public string GenerateIdFromName(string fullName)
        {
            if (fullName == null)
            {
                throw new ArgumentNullException(nameof(fullName));
            }

            return(NameAndIdProvider.CreateSanitizedId(ViewContext, fullName, IdAttributeDotReplacement));
        }
Example #3
0
        protected virtual string GenerateName(string expression)
        {
            var fullName = NameAndIdProvider.GetFullHtmlFieldName(ViewContext, expression);

            return(fullName);
        }