本文整理汇总了C#中System.Web.Mvc.HtmlHelper类的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper类的具体用法?C# HtmlHelper怎么用?C# HtmlHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HtmlHelper类属于System.Web.Mvc命名空间,在下文中一共展示了HtmlHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HiggsLabel
public HiggsLabel(HtmlHelper helper, ControlBase input, string text)
: base(helper, "label")
{
ForInputId = input.Id;
Text = text;
input.OnIdChange += MainInput_OnChangeId;
}
示例2: RenderFormGroupSelectElement
public static string RenderFormGroupSelectElement(HtmlHelper html, SelectElementModel inputModel,
LabelModel labelModel, InputType inputType)
{
HtmlString input = null;
if (inputType == InputType.DropDownList)
input = RenderSelectElement(html, inputModel, InputType.DropDownList);
if (inputType == InputType.ListBox)
input = RenderSelectElement(html, inputModel, InputType.ListBox);
var label = RenderLabel(html, labelModel ?? new LabelModel
{
htmlFieldName = inputModel.htmlFieldName,
metadata = inputModel.metadata,
htmlAttributes = new {@class = "control-label"}.ToDictionary()
});
var fieldIsValid = true;
if (inputModel != null)
fieldIsValid = html.ViewData.ModelState.IsValidField(inputModel.htmlFieldName);
return new FormGroup(input, label, FormGroupType.TextBoxLike, fieldIsValid).ToHtmlString();
}
示例3: RenderFormGroupCustom
public static string RenderFormGroupCustom(HtmlHelper html, FormGroupCustomModel customModel, LabelModel labelModel)
{
var label = RenderControl.RenderLabel(html, labelModel ?? new LabelModel
{
htmlFieldName = labelModel.htmlFieldName,
metadata = labelModel.metadata,
htmlAttributes = new { @class = "control-label" }.ToDictionary()
});
var htmlInput = customModel.input;
TagBuilder wrapper = null;
if (!string.IsNullOrEmpty(customModel.controlsElementWrapper))
{
wrapper = new TagBuilder(customModel.controlsElementWrapper);
if (customModel.controlsElementWrapperAttributes != null)
wrapper.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(customModel.controlsElementWrapperAttributes));
wrapper.InnerHtml = htmlInput.ToHtmlString();
}
HtmlString htmlString = wrapper != null
? new HtmlString(wrapper.ToString(TagRenderMode.Normal))
: htmlInput;
bool fieldIsValid = true;
if (labelModel != null && labelModel.htmlFieldName != null)
fieldIsValid = html.ViewData.ModelState.IsValidField(labelModel.htmlFieldName);
return new FormGroup(htmlString, label, FormGroupType.TextBoxLike, fieldIsValid).ToHtmlString();
}
示例4: GenerateUrl
private static string GenerateUrl(HtmlHelper htmlHelper, Route route, RouteValueDictionary routeValues)
{
//TODO: remove code dupe see UrlLinkToExtensions
var requestCtx = htmlHelper.ViewContext.RequestContext;
var httpCtx = requestCtx.HttpContext;
if (routeValues != null)
{
foreach (var d in route.Defaults)
{
if (!routeValues.ContainsKey(d.Key))
routeValues.Add(d.Key, d.Value);
}
}
else
{
routeValues = route.Defaults;
}
VirtualPathData vpd = route.GetVirtualPath(requestCtx, routeValues);
if (vpd == null)
return null;
return httpCtx.Request.ApplicationPath + vpd.VirtualPath;
}
示例5: ModelRendererBase
protected ModelRendererBase(HtmlHelper html, object model)
{
this.htmlHelper = html;
this.model = model;
this.htmlTextWriter = new HtmlTextWriter(new StringWriter());
}
示例6: MenuWriter
public MenuWriter(HtmlHelper htmlHelper, Menu menu, bool nest, object attributes)
{
this.htmlHelper = htmlHelper;
this.menu = menu;
this.nest = nest;
this.attributes = attributes;
}
示例7: AddNavigationNode
public static string AddNavigationNode(HtmlHelper htmlHelper, NavigationNode node)
{
StringBuilder nodeOutput = new StringBuilder();
if (node.Children.Count == 0)
{
nodeOutput.Append("<li>");
}
else
{
nodeOutput.Append("<li class=\"dropdown\">");
}
if (node.Children.Count == 0)
{
nodeOutput.Append(htmlHelper.ActionLink(node.Name, node.Action, node.Controller).ToString());
}
else
{
nodeOutput.Append(string.Format(@"<a href=""#"" class=""dropdown-toggle"" data-toggle=""dropdown"">{0}<b class=""caret""></b></a>", node.Name));
nodeOutput.Append(AddSubMenu(htmlHelper, node.Children));
}
nodeOutput.Append("</li>");
return nodeOutput.ToString();
}
示例8: ButtonTests
public ButtonTests()
{
var viewContext = new Mock<ViewContext>();
var viewDataContainer = new Mock<IViewDataContainer>();
_html = new HtmlHelper(viewContext.Object, viewDataContainer.Object);
}
示例9: Create
public static HtmlHelper Create()
{
var viewContext = new ViewContext();
var dataContainer = new Mock<IViewDataContainer>();
var htmlHelper = new HtmlHelper(viewContext, dataContainer.Object);
return htmlHelper;
}
示例10: GenerateTab
public string GenerateTab(ref HtmlHelper html, string text, string value)
{
var routeDataValues = html.ViewContext.RequestContext.RouteData.Values;
RouteValueDictionary pageLinkValueDictionary = new RouteValueDictionary { { Param, value } };
if (html.ViewContext.RequestContext.HttpContext.Request.QueryString["search"] != null)
pageLinkValueDictionary.Add("search", html.ViewContext.RequestContext.HttpContext.Request.QueryString["search"]);
if (!pageLinkValueDictionary.ContainsKey("id") && routeDataValues.ContainsKey("id"))
pageLinkValueDictionary.Add("id", routeDataValues["id"]);
// To be sure we get the right route, ensure the controller and action are specified.
if (!pageLinkValueDictionary.ContainsKey("controller") && routeDataValues.ContainsKey("controller"))
pageLinkValueDictionary.Add("controller", routeDataValues["controller"]);
if (!pageLinkValueDictionary.ContainsKey("action") && routeDataValues.ContainsKey("action"))
pageLinkValueDictionary.Add("action", routeDataValues["action"]);
// 'Render' virtual path.
var virtualPathForArea = RouteTable.Routes.GetVirtualPathForArea(html.ViewContext.RequestContext, pageLinkValueDictionary);
if (virtualPathForArea == null)
return null;
var stringBuilder = new StringBuilder("<li");
if (value == CurrentValue)
stringBuilder.Append(" class=active");
stringBuilder.AppendFormat("><a href={0}>{1}</a></li>", virtualPathForArea.VirtualPath, text);
return stringBuilder.ToString();
}
示例11: RibbonAppMenu
public RibbonAppMenu(HtmlHelper helper, string id, string title, string iconUrl = null)
: base(helper)
{
Id = id;
Title = title;
IconUrl = iconUrl;
}
示例12: RenderFormGroupRadioButton
public static string RenderFormGroupRadioButton(HtmlHelper html, RadioButtonModel inputModel, LabelModel labelModel)
{
var validationMessage = "";
var radioType = "form-icon";
if (inputModel.displayValidationMessage)
{
var validation = html.ValidationMessage(inputModel.htmlFieldName).ToHtmlString();
validationMessage = new HelpText(validation, inputModel.validationMessageStyle).ToHtmlString();
}
if (labelModel == null && inputModel.RadioType != InputRadioCheckBoxType._NotSet)
radioType = inputModel.RadioType.ToName();
var label = RenderLabel(html, labelModel ?? new LabelModel
{
htmlFieldName = inputModel.htmlFieldName,
metadata = inputModel.metadata,
innerInputType = InputType.Radio,
innerInputModel = inputModel,
innerValidationMessage = validationMessage,
htmlAttributes = new {@class = $"form-radio {radioType} form-text"}.ToDictionary()
});
var fieldIsValid = true;
if (inputModel != null)
fieldIsValid = html.ViewData.ModelState.IsValidField(inputModel.htmlFieldName);
return new FormGroup(null, label, FormGroupType.CheckBoxLike, fieldIsValid).ToHtmlString();
}
示例13: Create
/// <summary>
/// Create a new HtmlHelper with a fake context and container
/// </summary>
/// <returns>HtmlHelper</returns>
public static HtmlHelper Create()
{
var vc = new ViewContext();
vc.HttpContext = new FakeHttpContext();
var html = new HtmlHelper(vc, new FakeViewDataContainer());
return html;
}
示例14: Grid_GridSettingsIsNull_EmptyHtmlString
public void Grid_GridSettingsIsNull_EmptyHtmlString()
{
var html = new HtmlHelper(new ViewContext(), new ViewDataContainer());
MvcHtmlString grid = html.Grid(null);
Assert.AreEqual(string.Empty, grid.ToString());
}
示例15: RenderMainNav_RendersTheRootNodes
public void RenderMainNav_RendersTheRootNodes()
{
var mockContainer = new Mock<IViewDataContainer>();
var helper = new HtmlHelper( new ViewContext(), mockContainer.Object );
string result = helper.RenderMainNav( "Admin", new { @class = "myNav", id = "menu" } );
Assert.AreEqual( "<ul class='myNav' id='menu' ><li><a href='/Home/Index' title=HOME>HOME</a></li>\r\n<li><a href='/Dashboard/Index' title=Dashboard>Dashboard</a></li>\r\n<li><a href='/Administrator/Stats' title=My Stats>My Stats</a></li>\r\n</ul>", result );
}