예제 #1
0
        public static object GetInputValue(this HtmlHelper html, IFormInputBuilder inputBuilder, string name, object value, bool useViewData = false)
        {
            if (inputBuilder.InstanceData.ContainsKey("value"))
            {
                return(inputBuilder.Val());
            }

            if (useViewData && value == null)
            {
                value = Convert.ToString(html.ViewData.Eval(name), CultureInfo.CurrentCulture);
            }

            string fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);
            object attemptedValue    = html.GetModelStateValue(fullHtmlFieldName, typeof(string));

            return(attemptedValue ?? value);
        }
예제 #2
0
 /// <summary>
 /// Gets the value.
 /// </summary>
 public static object Val(this IFormInputBuilder instance)
 {
     return(instance.Prop <object>("value"));
 }
예제 #3
0
        public static object GetInputValue <TModel, TProperty>(this HtmlHelper <TModel> html, IFormInputBuilder inputBuilder, Expression <Func <TModel, TProperty> > expression)
        {
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);

            return(GetInputValue(html, inputBuilder, ExpressionHelper.GetExpressionText(expression), metadata.Model));
        }