public virtual void ContainsKey_is_true_for_dynamically_assigned_property() { var attributes = new HtmlAttributes(); ((dynamic)attributes).foo = "bar"; attributes.ContainsKey("foo").Should().BeTrue(); }
/// <summary> /// Merge the changes of CSS classes with HtmlAttributes /// </summary> private void MergeCssClasses() { if (_cssClasses.Count == 0 && HtmlAttributes.ContainsKey(CLASS)) { HtmlAttributes.Remove(CLASS); } else { HtmlAttributes[CLASS] = string.Join(" ", _cssClasses); } }
protected override void WriteHtml(HtmlTextWriter writer) { if (!HtmlAttributes.ContainsKey("id")) { HtmlAttributes["id"] = Id; } new ChartHtmlBuilder <T>(this) .Build() .WriteTo(writer); base.WriteHtml(writer); }
protected override void WriteHtml(System.Web.UI.HtmlTextWriter writer) { var htmlBuilder = new QRCodeHtmlBuilder(this); if (!HtmlAttributes.ContainsKey("id")) { HtmlAttributes["id"] = Id; } htmlBuilder .Build() .WriteTo(writer); base.WriteHtml(writer); }
/// <summary> /// Merges the specified attribute to the definition of this instance /// </summary> /// <param name="key">Attribute name</param> /// <param name="value">Attribute value</param> protected void MergeHtmlAttribute(string key, string value) { if (HtmlAttributes != null) { if (HtmlAttributes.ContainsKey(key)) { HtmlAttributes[key] = value; } else { HtmlAttributes.Add(key, value); } } else { HtmlAttributes = new Dictionary <string, object> { { key, value } }; } }
/// <summary> /// Called by the framework when the component needs to be rendered as HTML. /// </summary> /// <param name="model">The model being rendered by the component.</param> /// <returns>The component rendered as HTML.</returns> public Task <string> RenderAsync(object model) { YTagBuilder tag = new YTagBuilder("input"); FieldSetup(tag, FieldType.Normal); tag.MergeAttribute("type", "hidden"); if (HtmlAttributes.ContainsKey("--NoTemplate")) { HtmlAttributes.Remove("--NoTemplate"); } else if (HtmlAttributes.ContainsKey("__NoTemplate")) { HtmlAttributes.Remove("__NoTemplate"); } else { tag.AddCssClass("yt_hidden"); } if (model != null && model.GetType().IsEnum) { model = (int)model; } tag.MergeAttribute("value", model == null ? "" : model.ToString()); StringLengthAttribute lenAttr = PropData.TryGetAttribute <StringLengthAttribute>(); #if NOTYET if (lenAttr == null) { throw new InternalError($"No max string length given using StringLengthAttribute - {FieldName}"); } #endif if (lenAttr != null && lenAttr.MaximumLength > 0 && lenAttr.MaximumLength <= 8000) { tag.MergeAttribute("maxlength", lenAttr.MaximumLength.ToString()); } return(Task.FromResult(tag.ToString(YTagRenderMode.StartTag))); }
/// <summary> /// Called by the framework when the component needs to be rendered as HTML. /// </summary> /// <param name="model">The model being rendered by the component.</param> /// <returns>The component rendered as HTML.</returns> public Task <string> RenderAsync(string model) { HtmlBuilder hb = new HtmlBuilder(); hb.Append("<div class='yt_image t_display'>"); string imageType = PropData.GetAdditionalAttributeValue <string>("ImageType", null); int width = PropData.GetAdditionalAttributeValue("Width", 0); int height = PropData.GetAdditionalAttributeValue("Height", 0); if (string.IsNullOrWhiteSpace(imageType) && model != null && (model.IsAbsoluteUrl() || model.StartsWith("/") || model.StartsWith("data:"))) { if (width != 0 || height != 0) { throw new InternalError("Can't use Width or Height with external Urls"); } YTagBuilder img = new YTagBuilder("img"); img.Attributes.Add("src", model); if (!img.Attributes.ContainsKey("alt")) { img.Attributes.Add("alt", __ResStr("altImage", "Image")); } hb.Append(img.ToString(YTagRenderMode.Normal)); } else { if (string.IsNullOrWhiteSpace(imageType)) { throw new InternalError("No ImageType specified"); } bool showMissing = PropData.GetAdditionalAttributeValue("ShowMissing", true); if (string.IsNullOrWhiteSpace(model) && !showMissing) { return(Task.FromResult <string>(null)); } string alt = null; if (HtmlAttributes.ContainsKey("alt")) { alt = (string)HtmlAttributes["alt"]; } string imgTag = ImageComponentBase.RenderImage(imageType, width, height, model, Alt: alt); bool linkToImage = PropData.GetAdditionalAttributeValue("LinkToImage", false); if (linkToImage) { YTagBuilder link = new YTagBuilder("a"); string imgUrl = ImageHTML.FormatUrl(imageType, null, model); link.MergeAttribute("href", imgUrl); link.MergeAttribute("target", "_blank"); link.MergeAttribute("rel", "noopener noreferrer"); link.InnerHtml = imgTag; hb.Append(link.ToString(YTagRenderMode.Normal)); } else { hb.Append(imgTag); } } hb.Append("</div>"); return(Task.FromResult(hb.ToString())); }
protected override void WriteHtml(HtmlTextWriter writer) { if (!Columns.Any() && AutoGenerateColumns) { foreach (GridColumnBase <T> column in new GridColumnGenerator <T>(this).GetColumns()) { Columns.Add(column); } } var orignalClientValidationEnabled = ViewContext.ClientValidationEnabled; var originalFormContext = ViewContext.FormContext; try { ViewContext.ClientValidationEnabled = true; ViewContext.FormContext = new FormContext { FormId = Name + "form" }; if (Editable.Enabled && IsClientBinding) { InitializeEditors(); } AdjustColumnsTypesFromDynamic(); if (!HtmlAttributes.ContainsKey("id")) { HtmlAttributes["id"] = Id; } var builder = htmlBuilderFactory.CreateBuilder(Scrollable.Enabled); if (DataSource.Type != DataSourceType.Custom || DataSource.CustomType == "aspnetmvc-ajax") { ProcessDataSource(); } if (DataSource.Schema.Model.Id != null) { DataKeys.Add(DataSource.Schema.Model.Id); } var renderingData = CreateRenderingData(); var functionalData = CreateFunctionalData(); var container = builder.CreateGrid(HtmlAttributes, functionalData, renderingData); if (Editable.Mode == GridEditMode.PopUp && (CurrentItemMode == GridItemMode.Insert || CurrentItemMode == GridItemMode.Edit)) { AppendPopupEditor(container, renderingData); } container.WriteTo(writer); if (ViewContext.FormContext != null) { ValidationMetadata.Add("Fields", ProcessValidationMetadata()); ValidationMetadata.Add("FormId", ViewContext.FormContext.FormId); } } finally { ViewContext.FormContext = originalFormContext; ViewContext.ClientValidationEnabled = orignalClientValidationEnabled; } base.WriteHtml(writer); }
protected override void WriteHtml(HtmlTextWriter writer) { if (!Columns.Any() && AutoGenerateColumns) { foreach (GridColumnBase <T> column in new GridColumnGenerator <T>(this).GetColumns()) { Columns.Add(column); } } #if MVC2 || MVC3 var orignalClientValidationEnabled = ViewContext.ClientValidationEnabled; var originalFormContext = ViewContext.FormContext; try { ViewContext.ClientValidationEnabled = true; ViewContext.FormContext = new FormContext { FormId = Name + "form" }; if (Editing.Enabled && IsClientBinding) { InitializeEditors(); } #endif #if MVC3 AdjustColumnsTypesFromDynamic(); #endif RegisterScriptFiles(); if (!HtmlAttributes.ContainsKey("id")) { HtmlAttributes["id"] = Id; } var builder = htmlBuilderFactory.CreateBuilder(Scrolling.Enabled); var renderingData = CreateRenderingData(); var functionalData = CreateFunctionalData(); var container = builder.CreateGrid(HtmlAttributes, functionalData, renderingData); if (Editing.Mode == GridEditMode.PopUp && (CurrentItemMode == GridItemMode.Insert || CurrentItemMode == GridItemMode.Edit)) { AppendPopupEditor(container, renderingData); } container.WriteTo(writer); #if MVC2 || MVC3 if (ViewContext.FormContext != null) { ValidationMetadata.Add("Fields", ProcessValidationMetadata()); ValidationMetadata.Add("FormId", ViewContext.FormContext.FormId); } } finally { ViewContext.FormContext = originalFormContext; ViewContext.ClientValidationEnabled = orignalClientValidationEnabled; } #endif base.WriteHtml(writer); }