예제 #1
0
        /// <summary>
        /// Creates the framework control.
        /// </summary>
        /// <param name="context">Contains information associated with the current HTML tag.</param>
        /// <param name="output">A stateful HTML element used to generate an HTML tag.</param>
        /// <returns>The control instance.</returns>
        protected override IFWHtmlElement RenderControl(TagHelperContext context, TagHelperOutput output)
        {
            if (Id == null)
            {
                Id = TagBuilder.CreateSanitizedId(Path.GetFileNameWithoutExtension(ViewContext.View.Path), "_");
            }

            FWGridOptions options = CreateComponentConfig();

            // Gets the metadata from the return type of the service method.
            var metadata = RequestContext.MetadataProvider.GetMetadataForType(options.ServiceMethod.ReturnParameter.ParameterType);
            var control  = new FWGridControl(RequestContext, metadata, options)
            {
                AutoSizeColumns = AutoSizeColumns
            };

            control.Attributes.Add("data-control", "grid");
            if (AutoGenerateColumns.HasValue)
            {
                options.FluentConfiguration.Add(x => x.AutoGenerateColumns(AutoGenerateColumns.Value));
                control.AutoGenerateColumns(AutoGenerateColumns.Value);
            }

            context.Items["TemplateOptions"] = options;
            ChildContent.GetContent();

            return(control);
        }
예제 #2
0
        public IActionResult Load(FWDataOptionsViewModel bindModel)
        {
            var options = _memoryCache.Get <FWGridOptions>(bindModel.CId);

            if (options == null)
            {
                return(StatusCode(500, "bad model"));
            }

            var filter = FWMapperHelper.Transform(options.FilterType, bindModel);

            FWModelHelper.BindFilterFromQueryString(filter, HttpContext.Request.Query);

            HttpContext.SetView(options.ViewPath);

            var service = _serviceProvider.GetService(options.ServiceType);
            var model   = options.ServiceMethod.Invoke(service, new object[] { filter }) as IEnumerable;

            // Gets the metadata from the return type of the service method.
            var metadata = _requestContext.MetadataProvider.GetMetadataForType(options.ServiceMethod.ReturnParameter.ParameterType);
            var control  = new FWGridControl(_requestContext, metadata, model)
            {
                AutoSizeColumns = options.AutoSizeColumns
            };

            foreach (var config in options.FluentConfiguration)
            {
                config.Invoke(control);
            }

            return(Content(control.ToString()));
        }