public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            bool canHaveNames = ViewContext.GenerateNames();

            output.TagName = "input";
            output.Attributes.Add("type", "hidden");
            Type type = Encrypted ? typeof(EncryptedJsonTransformation <>) : typeof(JsonTransformation <>);

            type = type.MakeGenericType(new Type[] { For.ModelExplorer.ModelType });
            IBindingTransformation trasf = Activator.CreateInstance(type) as IBindingTransformation;

            trasf.Context = ViewContext.HttpContext;
            string res = type.GetMethod("Transform").Invoke(trasf, new object[] { For.Model }) as string;

            output.Attributes.Add("value", res);
            if (!canHaveNames)
            {
                if (!string.IsNullOrWhiteSpace(Name))
                {
                    output.Attributes.Add("name", Name);
                }
                else
                {
                    output.Attributes.Add("name", string.Empty);
                }
                if (!string.IsNullOrWhiteSpace(Id))
                {
                    output.Attributes.Add("id", Id);
                }
                else
                {
                    output.Attributes.Add("Id", string.Empty);
                }
            }
            else
            {
                string name     = combinePrefixes(For.Name, TransformationsRegister.GetPrefix(type));
                string fullName = ViewContext.ViewData.GetFullHtmlFieldName(name);
                if (string.IsNullOrWhiteSpace(Name))
                {
                    output.Attributes.Add("name", fullName);
                }
                else
                {
                    output.Attributes.Add("name", Name);
                }
                if (string.IsNullOrWhiteSpace(Id))
                {
                    output.Attributes.Add("id", TagBuilder.CreateSanitizedId(fullName, IdAttributeDotReplacement));
                }
                else
                {
                    output.Attributes.Add("id", Id);
                }
            }
            base.Process(context, output);
        }
예제 #2
0
 public void SetParameters(IHtmlContent content,
                           StandardButtons submitButton,
                           string controlType,
                           string headerBarName,
                           string footerBarName,
                           string submitBarName,
                           string name)
 {
     MainContent         = content;
     SubmitButton        = submitButton;
     ControlType         = controlType;
     HeaderBarName       = headerBarName;
     FooterBarName       = footerBarName;
     SubmitButton        = submitButton;
     Name                = name;
     OperationParameters = combinePrefixes(OperationParameters, TransformationsRegister.GetPrefix <JsonTransformation <QueryDescription> >());
 }
예제 #3
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (Transformation == null)
            {
                throw new ArgumentNullException(TransformationName);
            }
            Transformation.Context = ViewContext.HttpContext;
            var type = Transformation.GetType();

            var pres = type.GetMethod("Transform").Invoke(Transformation, new object[] { For.Model });

            var prefix = TransformationsRegister.GetPrefix(type);

            prefix         = combinePrefixes(For.Name, prefix);
            output.TagName = string.Empty;
            string childContent;

            if (string.IsNullOrWhiteSpace(UsePartial))
            {
                using (var scope = new RenderingScope(pres, ViewContext.ViewData.GetFullHtmlFieldName(prefix), ViewContext.ViewData))
                {
                    childContent = output.Content.IsModified ? output.Content.GetContent() :
                                   (await output.GetChildContentAsync()).GetContent();
                }
            }
            else
            {
                var sw   = new StringWriter();
                var prov = ViewContext.HttpContext.RequestServices.GetRequiredService <IModelMetadataProvider>();
                var dict = new ViewDataDictionary(prov, ViewContext.ViewData.ModelState);
                dict.Model = pres;
                dict.TemplateInfo.HtmlFieldPrefix     = ViewContext.ViewData.GetFullHtmlFieldName(prefix);
                dict[TagHelpersProviderContext.Field] = ViewContext.ViewData[TagHelpersProviderContext.Field];
                var newContext = new ViewContext(ViewContext, ViewContext.View, dict, ViewContext.TempData, sw,
                                                 new HtmlHelperOptions {
                    Html5DateRenderingMode          = ViewContext.Html5DateRenderingMode,
                    ClientValidationEnabled         = ViewContext.ClientValidationEnabled,
                    ValidationMessageElement        = ViewContext.ValidationMessageElement,
                    ValidationSummaryMessageElement = ViewContext.ValidationSummaryMessageElement
                });
                childContent = await newContext.RenderPartialView(UsePartial);
            }
            output.Content.SetHtmlContent(childContent);
        }
예제 #4
0
        private Type getTransformation(ModelBindingContext bindingContext, out Type fitype, out Type fdtype, out string index)
        {
            fitype = null;  fdtype = null; index = null;
            var httpContext = bindingContext.HttpContext;
            var tr          = httpContext.RequestServices.GetService <RequestTransformationsRegister>();

            if (tr == null)
            {
                return(null);
            }
            index = tr.GetIndex(bindingContext.ModelName ?? string.Empty);
            if (index == null)
            {
                return(null);
            }
            if (index.Length > 0 && index[index.Length - 1] == '_')
            {
                return(DerivedClassesRegister.GetTypeFromCode(index));
            }
            else
            {
                return(TransformationsRegister.InverseTransform(bindingContext.ModelMetadata.ModelType, index, out fitype, out fdtype));
            }
        }
        private IHtmlContent buttonAttributes()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("data-operation='");
            sb.Append(
                options.Type == QueryWindowType.Filtering ? "query-filtering " :
                (options.Type == QueryWindowType.Sorting ? "query-sorting " :
                 (options.Type == QueryWindowType.Grouping ? "query-grouping " : "query-back ")));
            string queryName = null;

            if (options.Type == QueryWindowType.Back)
            {
                queryName = combinePrefixes(helpers.Context.ViewData.GetFullHtmlFieldName(this.options.For.Name), TransformationsRegister.GetPrefix <JsonTransformation <QueryDescription> >());
            }
            else
            {
                queryName = helpers.Html.GenerateIdFromName(helpers.Context.ViewData.GetFullHtmlFieldName(this.options.For.Name));
            }
            sb.Append(queryName);
            if (options.Url != null)
            {
                sb.Append(" ");
                sb.Append(HtmlEncoder.Default.Encode(options.Url));
            }
            if (options.AjaxId != null)
            {
                sb.Append(" ");
                sb.Append("." + options.AjaxId);
            }
            sb.Append("'");
            return(new HtmlString(sb.ToString()));
        }