本文整理汇总了C#中TagBuilder.AddCssStyle方法的典型用法代码示例。如果您正苦于以下问题:C# TagBuilder.AddCssStyle方法的具体用法?C# TagBuilder.AddCssStyle怎么用?C# TagBuilder.AddCssStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TagBuilder
的用法示例。
在下文中一共展示了TagBuilder.AddCssStyle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderLabel
public static HtmlString RenderLabel(HtmlHelper html, LabelModel model)
{
var fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(model.htmlFieldName);
var innerinput = "";
if (string.IsNullOrEmpty(model.labelText))
model.labelText = model.metadata.DisplayName
?? (model.metadata.PropertyName != null ? model.metadata.PropertyName.SplitByUpperCase() : null)
?? fullHtmlFieldName.Split('.').Last().SplitByUpperCase();
var label = new TagBuilder("label");
label.Attributes.Add("for",
fullHtmlFieldName.FormatForMvcInputId() + (model.index.HasValue ? "_" + model.index.Value : string.Empty));
label.MergeAttributes(model.htmlAttributes.FormatHtmlAttributes());
var requiredSpan = new TagBuilder("span");
requiredSpan.AddCssClass("required");
requiredSpan.SetInnerText("*");
if ((model.showRequiredStar.HasValue && !model.showRequiredStar.Value) ||
(!model.showRequiredStar.HasValue && !model.metadata.IsRequired))
requiredSpan.AddCssStyle("visibility", "hidden");
if (model.innerInputType != InputType._NotSet)
{
if (model.innerInputType == InputType.CheckBox)
{
var inputModel = (CheckBoxModel) model.innerInputModel;
//label.AddOrMergeCssClass("checkbox");
inputModel.displayValidationMessage = false;
model.innerInput = MvcHtmlString.Create(inputModel.isSingleInput
? RenderCheckBoxCustom(html, inputModel).ToHtmlString()
: RenderCheckBox(html, inputModel).ToHtmlString());
if (inputModel.htmlAttributes.Keys.Select(x => x.ToLower()).Contains("id"))
label.Attributes["for"] = inputModel.htmlAttributes["id"].ToString();
}
if (model.innerInputType == InputType.Radio)
{
var inputModel = (RadioButtonModel) model.innerInputModel;
model.innerInput = MvcHtmlString.Create(RenderRadioButton(html, inputModel).ToHtmlString());
if (inputModel.htmlAttributes.Keys.Select(x => x.ToLower()).Contains("id"))
label.Attributes["for"] = inputModel.htmlAttributes["id"].ToString();
}
}
if (model.innerInput != null)
innerinput = model.innerInput.ToHtmlString();
label.InnerHtml = innerinput + model.labelText + requiredSpan + model.innerValidationMessage;
return new HtmlString(label.ToString(TagRenderMode.Normal));
}
示例2: RenderDisplayText
public static string RenderDisplayText(HtmlHelper html, BootstrapDisplayTextModel model)
{
var input = html.DisplayText(model.htmlFieldName);
TagBuilder containerDiv = new TagBuilder("div");
containerDiv.MergeAttributes(model.htmlAttributes.FormatHtmlAttributes());
containerDiv.AddCssStyle("padding-top", "5px");
containerDiv.InnerHtml = input.ToHtmlString();
return containerDiv.ToString(TagRenderMode.Normal);
}
示例3: RenderRadioButtonTrueFalse
public static string RenderRadioButtonTrueFalse(HtmlHelper html, BootstrapRadioButtonTrueFalseModel model)
{
TagBuilder inputsContainer = new TagBuilder("div");
inputsContainer.AddCssClass("container-radio-true-false");
inputsContainer.AddCssStyle("display", "inline-block");
inputsContainer.AddCssStyle("margin-top", "4px");
if (model.tooltipConfiguration != null) inputsContainer.MergeAttributes(model.tooltipConfiguration.ToDictionary());
if (model.tooltip != null) inputsContainer.MergeAttributes(model.tooltip.ToDictionary());
string fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(model.htmlFieldName);
bool trueValueIsSelected = false;
bool falseValueIsSelected = false;
if (model.metadata.Model != null)
{
trueValueIsSelected = model.inputTrueValue.ToString() == model.metadata.Model.ToString();
falseValueIsSelected = model.inputTrueValue.ToString() != model.metadata.Model.ToString();
}
var inputTrue = Renderer.RenderLabel(html, new BootstrapLabelModel
{
htmlFieldName = model.htmlFieldName,
labelText = model.labelTrueText,
metadata = model.metadata,
htmlAttributes = model.htmlAttributesLabelTrue,
showRequiredStar = false,
innerInputType = BootstrapInputType.Radio,
innerInputModel = new BootstrapRadioButtonModel
{
htmlFieldName = model.htmlFieldName,
value = model.inputTrueValue,
metadata = model.metadata,
isChecked = trueValueIsSelected,
htmlAttributes = model.htmlAttributesInputTrue.AddOrReplace("id", fullHtmlFieldName.FormatForMvcInputId() + "_t")
}
});
var inputFalse = Renderer.RenderLabel(html, new BootstrapLabelModel
{
htmlFieldName = model.htmlFieldName,
labelText = model.labelFalseText,
metadata = model.metadata,
htmlAttributes = model.htmlAttributesLabelFalse,
showRequiredStar = false,
innerInputType = BootstrapInputType.Radio,
innerInputModel = new BootstrapRadioButtonModel
{
htmlFieldName = model.htmlFieldName,
value = model.inputFalseValue,
metadata = model.metadata,
isChecked = falseValueIsSelected,
htmlAttributes = model.htmlAttributesInputFalse.AddOrReplace("id", fullHtmlFieldName.FormatForMvcInputId() + "_f")
}
});
string helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
string validationMessage = "";
if (model.displayValidationMessage)
{
string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
}
inputsContainer.InnerHtml = inputTrue + inputFalse;
return inputsContainer.ToString() + helpText + validationMessage;
}
示例4: RenderInputListContainer
public static string RenderInputListContainer(
HtmlHelper html,
string htmlFieldName,
List<string> inputs,
int? numberOfColumns,
bool displayInColumnsCondition,
int columnPixelWidth,
bool displayInlineBlock,
int marginRightPx,
bool displayValidationMessage,
HelpTextStyle validationMessageStyle
)
{
TagBuilder container = new TagBuilder("div");
container.AddCssClass("input-list-container");
if (displayValidationMessage)
{
//container.AddCssStyle("display", "inline-block");
//container.AddCssStyle("vertical-align", "middle");
//container.AddCssStyle("margin-top", "4px");
}
if (numberOfColumns.HasValue && displayInColumnsCondition)
{
container.AddCssStyle("max-width", (columnPixelWidth * numberOfColumns).ToString() + "px");
List<string> columnedInputs = new List<string>();
TagBuilder columnDiv = new TagBuilder("div");
//columnDiv.AddCssClass("input-list-column");
//columnDiv.AddCssStyle("width", columnPixelWidth.ToString() + "px");
//columnDiv.AddCssStyle("display", "inline-block");
foreach (var input in inputs)
{
columnDiv.InnerHtml = input;
columnedInputs.Add(columnDiv.ToString());
}
inputs = columnedInputs;
}
if (displayInlineBlock)
{
List<string> columnedInputs = new List<string>();
TagBuilder columnDiv = new TagBuilder("div");
//columnDiv.AddCssClass("input-list-inline");
//columnDiv.AddCssStyle("display", "inline-block");
//columnDiv.AddCssStyle("margin-right", marginRightPx.ToString() + "px");
foreach (var input in inputs)
{
columnDiv.InnerHtml = input;
columnedInputs.Add(columnDiv.ToString());
}
inputs = columnedInputs;
}
string inputsCombined = string.Empty;
inputs.ForEach(c => inputsCombined += c);
container.InnerHtml = inputsCombined;
string validationMessage = "";
if (displayValidationMessage && html.ValidationMessage(htmlFieldName) != null)
{
string validation = html.ValidationMessage(htmlFieldName).ToHtmlString();
validationMessage = new BootstrapHelpText(validation, validationMessageStyle).ToHtmlString();
}
return container.ToString(TagRenderMode.Normal) + validationMessage;
}
示例5: RenderInputListContainer
public static HtmlString RenderInputListContainer(HtmlHelper html, string htmlFieldName, List<string> inputs,
int? numberOfColumns, bool displayInColumnsCondition,
int columnPixelWidth, bool displayInlineBlock, int marginRightPx, bool displayValidationMessage,
HelpTextStyle validationMessageStyle, InputType inputType, CheckBoxRadioStyle inputStyle)
{
var cssClass = inputType == InputType.CheckBoxList ? "checkbox" : "radio";
var displayStyle = inputStyle == CheckBoxRadioStyle.Block ? "form-block" : "form-inline";
var container = new TagBuilder("div");
container.AddCssClass($"{cssClass} {displayStyle}");
if (displayValidationMessage)
{
container.AddCssStyle("display", "inline-block");
container.AddCssStyle("vertical-align", "middle");
container.AddCssStyle("margin-top", "4px");
}
if (numberOfColumns.HasValue && displayInColumnsCondition)
{
container.AddCssStyle("max-width", columnPixelWidth*numberOfColumns + "px");
var columnedInputs = new List<string>();
var columnDiv = new TagBuilder("div");
columnDiv.AddCssClass("input-list-column");
columnDiv.AddCssStyle("width", columnPixelWidth + "px");
columnDiv.AddCssStyle("display", "inline-block");
foreach (var input in inputs)
{
columnDiv.InnerHtml = input;
columnedInputs.Add(columnDiv.ToString());
}
inputs = columnedInputs;
}
if (displayInlineBlock)
{
var columnedInputs = new List<string>();
var columnDiv = new TagBuilder("div");
columnDiv.AddCssClass("input-list-inline");
columnDiv.AddCssStyle("display", "inline-block");
columnDiv.AddCssStyle("margin-right", marginRightPx + "px");
foreach (var input in inputs)
{
columnDiv.InnerHtml = input;
columnedInputs.Add(columnDiv.ToString());
}
inputs = columnedInputs;
}
var inputsCombined = string.Empty;
inputs.ForEach(c => inputsCombined += c);
container.InnerHtml = inputsCombined;
var validationMessage = "";
if (displayValidationMessage)
{
var validation = html.ValidationMessage(htmlFieldName).ToHtmlString();
validationMessage = new HelpText(validation, validationMessageStyle).ToHtmlString();
}
return new HtmlString(container.ToString(TagRenderMode.Normal) + validationMessage);
}