Exemplo n.º 1
0
        protected virtual string GenerateValue(string expression, object value, string format, bool useViewData)
        {
            var fullName       = DefaultHtmlGenerator.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);
        }
Exemplo n.º 2
0
        protected virtual string GenerateId(string expression)
        {
            var fullName = DefaultHtmlGenerator.GetFullHtmlFieldName(ViewContext, expression: expression);
            var id       = TagBuilder.CreateSanitizedId(fullName, IdAttributeDotReplacement);

            return(id);
        }
Exemplo n.º 3
0
        protected virtual string GenerateName(string expression)
        {
            var fullName = DefaultHtmlGenerator.GetFullHtmlFieldName(ViewContext, expression);

            return(fullName);
        }