Exemple #1
0
 public static IEnumerable <IDictionary <string, object> > GetValidationRulesByPropertyName(string propertyName, ViewContext viewContext)
 {
     if (!string.IsNullOrEmpty(propertyName))
     {
         ModelExplorer modelExplorer = Portability.GetModelExpressionProvider(viewContext).GetModelExplorer(propertyName, viewContext.ViewData);
         return(GetValidationRules(propertyName, modelExplorer, viewContext));
     }
     return(Enumerable.Empty <IDictionary <string, object> >());
 }
Exemple #2
0
        public static void PrepareEditorFor <TModel, TProperty>(this WidgetBuilder builder, IHtmlHelperAdapter html, Expression <Func <TModel, TProperty> > expression)
        {
            ViewContext viewContext = html.ViewContext;

            Portability.IModelExpressionProviderAdapter modelExpressionProvider = Portability.GetModelExpressionProvider(viewContext);
            ModelExplorer modelExplorer  = modelExpressionProvider.GetModelExplorer(expression, new ViewDataDictionary <TModel>(viewContext.ViewData));
            string        expressionText = modelExpressionProvider.GetExpressionText(expression);

            builder.Options["name"]  = expressionText;
            builder.Options["value"] = modelExplorer?.Model;
            builder.ValidationRules  = DataAnnotationsHelper.GetValidationRules(expressionText, modelExplorer, viewContext);
        }
 private static string GetExpressionText <M, P>(IHtmlHelperAdapter html, Expression <Func <M, P> > expr)
 {
     return(Portability.GetModelExpressionProvider(html.ViewContext).GetExpressionText(expr));
 }
        private static ModelExplorer GetModelExplorer <TModel, TProperty>(IHtmlHelperAdapter html, Expression <Func <TModel, TProperty> > expression)
        {
            ViewDataDictionary <TModel> viewData = new ViewDataDictionary <TModel>(html.ViewContext.ViewData, null);

            return(Portability.GetModelExpressionProvider(html.ViewContext).GetModelExplorer(expression, viewData));
        }