コード例 #1
0
        private static void UpdateModel(ListViewModel listViewModel, ControllerContext controllerContext, string[] includeProperties, string[] excludeProperties)
        {
            var modelBindingContext = new ModelBindingContext
                                          {
                                              ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => listViewModel, listViewModel.GetType()),
                                              ValueProvider = ValueProviderFactories.Factories.GetValueProvider(controllerContext),
                                              ModelState = listViewModel.ModelState,
                                              PropertyFilter = propertyName => IsPropertyAllowed(propertyName, includeProperties, excludeProperties),
                                          };

            ModelBinders.Binders.GetBinder(typeof(ListViewModel)).BindModel(controllerContext, modelBindingContext);
        }
コード例 #2
0
        public ListViewModel GetListViewModelForType(Type type, ControllerContext controllerContext, ListViewModelOptions options)
        {
            var urlHelper = new UrlHelper(controllerContext.RequestContext);
            var listViewModel = new ListViewModel {Columns = listColumnProvider.GetColumnsForType(type, controllerContext)};

            UpdateModel(listViewModel, controllerContext, options.ListViewModelIncludeProperties, options.ListViewModelExcludeProperties);

            if(options.RenderOptions != null)
                listViewModel.RenderOptions = options.RenderOptions;

            listViewModel.SearchUrl = urlHelper.Action(options.SearchAction, new {listViewModel.SortBy, listViewModel.SortDirection});
            listViewModel.TitleViewName = ViewEngines.Engines.FindPartialViewOrDefault(controllerContext, options.TitleViewName, options.DefaultTitleViewName);
            listViewModel.ButtonsViewName = ViewEngines.Engines.FindPartialViewOrDefault(controllerContext, options.ButtonsViewName, options.DefaultButtonsViewName);
            listViewModel.PagerViewName = ViewEngines.Engines.FindPartialViewOrDefault(controllerContext, options.PagerViewName, options.DefaultPagerViewName);
            listViewModel.RowsViewName = ViewEngines.Engines.FindPartialViewOrDefault(controllerContext, options.RowsViewName, options.DefaultRowsViewName);
            listViewModel.SearchViewName = ViewEngines.Engines.FindPartialViewOrDefault(controllerContext, options.SearchFormViewName, options.DefaultSearchFormViewName);
            listViewModel.Title = options.Title ?? GetDefaultTitle(controllerContext.Controller);
            listViewModel.Subtitle = options.Subtitle;

            return listViewModel;
        }
コード例 #3
0
        public void Setup()
        {
            form = new NameValueCollection();
            columns = new ListColumns();
            listViewModel = new ListViewModel {Columns = columns};
            httpContext = new MockHttpContext();
            ((MockHttpRequest)httpContext.Request).SetForm(form);

            controllerContext = new ControllerContext();
            controllerContext.HttpContext = httpContext;

            ValueProviderFactories.Factories
                .ReplaceWith<HttpFileCollectionValueProviderFactory>(ctx => ctx.HttpContext.Request.Form)
                .ReplaceWith<FormValueProviderFactory>(ctx => ctx.HttpContext.Request.Form)
                .ReplaceWith<QueryStringValueProviderFactory>(ctx => ctx.HttpContext.Request.QueryString);

            bindingContext = new ModelBindingContext
                                 {
                                     ModelMetadata = ModelMetadata.FromLambdaExpression(parameter => parameter, new ViewDataDictionary<ListViewModel>(listViewModel))
                                 };

            binder = new ListViewModelBinder();
        }