protected void RenderAspFor(TagHelperContext context, TagHelperOutput output) { if (AspFor != null) { var buffer = new TagHelperOutput("input", new TagHelperAttributeList(), (cache, encoder) => Task.FromResult <TagHelperContent>(new DefaultTagHelperContent())); var helper = new InputTagHelper(HtmlGenerator); helper.ViewContext = ViewContext; helper.For = AspFor; //helper.InputTypeName = InputType; helper.Init(context); helper.Process(context, buffer); MvcTagHelperOutput = buffer; Debug.WriteLine(MvcTagHelperOutput.ToTagHelperContent().GetContent()); foreach (TagHelperAttribute attr in buffer.Attributes) { if (!attr.Name.StartsWith("data-")) { output.MergeAttribute(attr.Name, attr.Value); } } if (string.IsNullOrEmpty(LabelText)) { LabelText = AspFor.Metadata.DisplayName ?? AspFor.Metadata.PropertyName; } if (string.IsNullOrEmpty(HelpText)) { HelpText = AspFor.Metadata.Description; } } }
public override void Process(TagHelperContext context, TagHelperOutput output) { string input = ""; string labelCss = "col-sm-4"; string controlCss = "col-sm-8"; var helper = new InputTagHelper(Generator); helper.ViewContext = ViewContext; helper.For = Value; helper.Init(context); helper.Process(context, output); using (var writer = new StringWriter()) { output.TagName = "input"; if (output.Attributes.ContainsName("Value")) { var val = output.Attributes["Value"]; if (val.Value?.ToString().ToLower() == "true") { output.Attributes.Add("checked", ""); } } output.WriteTo(writer, HtmlEncoder.Default); input = writer.ToString().Replace("text", "checkbox"); } output.Attributes.Clear(); output.PostContent.Clear(); output.Content.Clear(); var label = Label ?? Value?.Metadata?.DisplayName ?? Value?.Name ?? ""; var labelContent = $"<label for='{Value.Name}' class='{labelCss} col-form-label'>{label}</label>"; var validateBuilder = Generator.GenerateValidationMessage( ViewContext, Value.ModelExplorer, Value.Name, message: null, tag: null, htmlAttributes: null); var divBuilder = new TagBuilder("div"); divBuilder.AddCssClass(controlCss); divBuilder.AddCssClass("col-form-checkbox"); divBuilder.InnerHtml.AppendHtml(input); divBuilder.InnerHtml.AppendHtml(validateBuilder); output.TagName = "div"; output.Attributes.Add("class", "form-group row"); output.Content.AppendHtml(labelContent); output.Content.AppendHtml(divBuilder); }
public override void Process(TagHelperContext context, TagHelperOutput output) { string input = ""; string labelCss = "col-sm-4"; string controlCss = "col-sm-8"; var helper = new InputTagHelper(Generator); helper.ViewContext = ViewContext; helper.For = Value; helper.Init(context); helper.Process(context, output); using (var writer = new StringWriter()) { output.TagName = "input"; output.Attributes.Add("class", "form-control"); output.Attributes.Add("placeholder", Placeholder); output.WriteTo(writer, HtmlEncoder.Default); input = writer.ToString().Replace("number", "text"); } output.Attributes.Clear(); output.PostContent.Clear(); output.Content.Clear(); string req = (input.IndexOf("data-val-required") > -1) ? "<span class='required'>*</span>" : ""; var label = Label ?? Value?.Metadata?.DisplayName ?? Value?.Name ?? ""; var labelContent = $"<label for='{Value.Name}' class='{labelCss} col-form-label'>{req}{label}</label>"; var validateBuilder = Generator.GenerateValidationMessage( ViewContext, Value.ModelExplorer, Value.Name, message: null, tag: null, htmlAttributes: null); var divBuilder = new TagBuilder("div"); divBuilder.AddCssClass(controlCss); divBuilder.InnerHtml.AppendHtml(input); divBuilder.InnerHtml.AppendHtml(validateBuilder); output.TagName = "div"; output.Attributes.Add("class", "form-group row"); output.Content.AppendHtml(labelContent); output.Content.AppendHtml(divBuilder); }
public override void Process(TagHelperContext context, TagHelperOutput output) { var helper = new InputTagHelper(Generator); helper.ViewContext = ViewContext; helper.For = For; helper.Init(context); helper.Process(context, output); string name = For.Name.Substring(For.Name.LastIndexOf('.') + 1).ToLower(); output.Attributes.SetAttribute(":id", $"`${{id}}.{ name }`"); output.Attributes.SetAttribute(":name", $"`${{id}}.{ name }`"); }
private IHtmlContent CreateInputElement(TagHelperContext context) { // Create combination of two inputs, one visible for file name, one hidden for file id // Create name input IHtmlContent nameInputContent; if (IsSearchEnabled) { var nameInputTagHelper = new EntitySearchTagHelper(Generator) { Type = typeof(File).Name, Value = (FileProperty.Model as File)?.Name, Class = "file-name-input", FilterName = "category", FilterValue = CategoryString, ViewContext = ViewContext }; var nameInputOutput = CreateTagHelperOutput("search"); nameInputTagHelper.Process(context, nameInputOutput); nameInputContent = nameInputOutput; } else { var nameInput = new TagBuilder("input"); nameInput.Attributes.Add("type", "text"); nameInput.Attributes.Add("class", "form-control file-name-input"); nameInput.Attributes.Add("readonly", "readonly"); nameInput.Attributes.Add("value", (FileProperty.Model as File)?.Name); nameInputContent = nameInput; } // create id input var idInputHelper = new InputTagHelper(Generator) { For = For, ViewContext = ViewContext }; var idInputContent = CreateTagHelperOutput("input"); idInputHelper.Process(context, idInputContent); idInputContent.Attributes.Add("class", "file-id-input"); idInputContent.Attributes.SetAttribute("type", "hidden"); idInputContent.Attributes.Add("value", For.Model?.ToString()); // return input combination return(WrapInDiv(new[] { nameInputContent, idInputContent })); }
private IHtmlContent CreateHiddenElement(TagHelperContext context) { var hidden = new InputTagHelper(Generator) { For = For, //InputTypeName = "hidden", ViewContext = ViewContext }; var output = CreateTagHelperOutput("input"); hidden.Process(context, output); output.Attributes.SetAttribute("type", "hidden"); return(output); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (!NotEdit) { var inputContext = CrateTagHelperContext(); var inputOutput = CreateTagHelperOutput("input"); inputOutput.Attributes.Add("class", "form-control"); var input = new InputTagHelper(_htmlGenerator) { For = For, ViewContext = ViewContext }; input.Process(inputContext, inputOutput); output.Content.AppendHtml(inputOutput); } else { var labelContext = CrateTagHelperContext(); var labelOutput = CreateTagHelperOutput("label"); //labelOutput.Content.Append(LabelContent); if (For != null) { labelOutput.Attributes.Add("for", For.Name); } var label = new LabelTagHelper(_htmlGenerator) { ViewContext = ViewContext }; label.Process(labelContext, labelOutput); output.Content.AppendHtml(labelOutput); } }
public override void Process(TagHelperContext context, TagHelperOutput output) { string input = ""; var helper = new InputTagHelper(Generator); helper.ViewContext = ViewContext; helper.For = Value; helper.Init(context); helper.Process(context, output); string ischecked = Value?.Model?.ToString() == "True" ? "checked='checked'" : ""; input = $"<input type='checkbox' disabled='disabled' {ischecked} >"; output.Attributes.Clear(); output.PostContent.Clear(); output.Content.Clear(); var value = Value?.Model?.ToString(); var label = Label ?? Value?.Metadata?.DisplayName ?? Value?.Name ?? ""; var encoder = HtmlEncoder.Create(allowedRanges: new[] { UnicodeRanges.BasicLatin, UnicodeRanges.CjkUnifiedIdeographs }); value = encoder.Encode(value ?? ""); label = encoder.Encode(label ?? ""); var labelContent = $"<label for='{Value.Name}' class='col-sm-4 col-form-label'>{label}</label>"; var valueContent = $"<div class='col-sm-8 col-form-checkbox'>{input}</div>"; output.TagName = "div"; output.Attributes.Add("class", "form-group row"); output.Content.AppendHtml(labelContent); output.Content.AppendHtml(valueContent); }