本文整理汇总了C#中System.Web.WebPages.Html.HtmlHelper类的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper类的具体用法?C# HtmlHelper怎么用?C# HtmlHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HtmlHelper类属于System.Web.WebPages.Html命名空间,在下文中一共展示了HtmlHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: DropDownListThrowsWithNoName
public void DropDownListThrowsWithNoName() {
// Arrange
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act and assert
ExceptionAssert.ThrowsArgNullOrEmpty(() => helper.DropDownList(name: null, selectList: null), "name");
}
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:7,代码来源:SelectHelperTest.cs
示例2: RadioButtonWithEmptyNameThrows
public void RadioButtonWithEmptyNameThrows() {
// Arrange
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act and assert
ExceptionAssert.ThrowsArgNullOrEmpty(() => helper.RadioButton(null, null), "name");
ExceptionAssert.ThrowsArgNullOrEmpty(() => helper.RadioButton(String.Empty, null), "name");
}
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:8,代码来源:RadioButtonTest.cs
示例3: ValidationMessageWithNoErrorResultsInNullString
public void ValidationMessageWithNoErrorResultsInNullString() {
// Arrange
HtmlHelper htmlHelper = new HtmlHelper(new ModelStateDictionary());
// Act
var html = htmlHelper.ValidationMessage("does-not-exist");
Assert.IsNull(html);
}
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:9,代码来源:ValidationHelperTest.cs
示例4: TextAreaWithDefaultRowsAndCols
public void TextAreaWithDefaultRowsAndCols() {
// Arrange
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act
var html = helper.TextArea("foo");
// Assert
Assert.AreEqual(@"<textarea cols=""20"" id=""foo"" name=""foo"" rows=""2""></textarea>", html.ToHtmlString());
}
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:10,代码来源:TextAreaHelperTest.cs
示例5: TextAreaWithEmptyNameThrows
public void TextAreaWithEmptyNameThrows() {
// Arrange
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act and assert
ExceptionAssert.ThrowsArgumentException(() => helper.TextArea(null), "name", "Value cannot be null or an empty string.");
// Act and assert
ExceptionAssert.ThrowsArgumentException(() => helper.TextArea(String.Empty), "name", "Value cannot be null or an empty string.");
}
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:10,代码来源:TextAreaHelperTest.cs
示例6: ValidationMessageReturnsWithCustomMessageAndObjectAttributes
public void ValidationMessageReturnsWithCustomMessageAndObjectAttributes() {
// Arrange
HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());
// Act
var html = htmlHelper.ValidationMessage("foo", "bar error", new { baz = "baz" });
// Assert
Assert.AreEqual(@"<span baz=""baz"" class=""field-validation-error"">bar error</span>", html.ToHtmlString());
}
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:10,代码来源:ValidationHelperTest.cs
示例7: TextAreaWithNonZeroRowsAndColumns
public void TextAreaWithNonZeroRowsAndColumns() {
// Arrange
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act
var html = helper.TextArea("foo", null, 4, 10, null);
// Assert
Assert.AreEqual(@"<textarea cols=""10"" id=""foo"" name=""foo"" rows=""4""></textarea>", html.ToHtmlString());
}
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:10,代码来源:TextAreaHelperTest.cs
示例8: ValidationMessageReturnsWithCustomMessage
public void ValidationMessageReturnsWithCustomMessage() {
// Arrange
HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());
// Atc
var html = htmlHelper.ValidationMessage("foo", "bar error");
// Assert
Assert.AreEqual(@"<span class=""field-validation-error"">bar error</span>", html.ToHtmlString());
}
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:10,代码来源:ValidationHelperTest.cs
示例9: ValidationMessageReturnsWithObjectAttributes
public void ValidationMessageReturnsWithObjectAttributes() {
// Arrange
HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());
// Act
var html = htmlHelper.ValidationMessage("foo", new { attr = "attr-value" });
// Assert
Assert.AreEqual(@"<span attr=""attr-value"" class=""field-validation-error"">foo error <1></span>", html.ToHtmlString());
}
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:10,代码来源:ValidationHelperTest.cs
示例10: ValidationMessageReturnsNullForInvalidName
public void ValidationMessageReturnsNullForInvalidName() {
// Arrange
HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());
// Act
var html = htmlHelper.ValidationMessage("baz");
// Assert
Assert.IsNull(html, "html should be null if name is invalid.");
}
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:10,代码来源:ValidationHelperTest.cs
示例11: ValidationMessageReturnsFirstError
public void ValidationMessageReturnsFirstError() {
// Arrange
HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());
// Act
var html = htmlHelper.ValidationMessage("foo");
// Assert
Assert.AreEqual(@"<span class=""field-validation-error"">foo error <1></span>", html.ToHtmlString());
}
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:10,代码来源:ValidationHelperTest.cs
示例12: RadioButtonWithDictionaryAttributes
public void RadioButtonWithDictionaryAttributes() {
// Arrange
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act
var html = helper.RadioButton("foo", "bar", new Dictionary<string, object> { { "attr", "attr-value" } });
// Assert
Assert.AreEqual(@"<input attr=""attr-value"" id=""foo"" name=""foo"" type=""radio"" value=""bar"" />",
html.ToHtmlString());
}
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:11,代码来源:RadioButtonTest.cs
示例13: EncodeStringNull
public void EncodeStringNull() {
// Arrange
HtmlHelper htmlHelper = new HtmlHelper(new ModelStateDictionary());
string text = null;
// Act
string encodedHtml = htmlHelper.Encode(text);
// Assert
Assert.AreEqual("", encodedHtml);
}
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:11,代码来源:HtmlHelperTest.cs
示例14: EncodeString
public void EncodeString() {
// Arrange
HtmlHelper htmlHelper = new HtmlHelper(new ModelStateDictionary());
var text = "<br />";
// Act
string encodedHtml = htmlHelper.Encode(text);
// Assert
Assert.AreEqual(encodedHtml, "<br />", "Text is not being properly HTML-encoded.");
}
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:11,代码来源:HtmlHelperTest.cs
示例15: EncodeObjectNull
public void EncodeObjectNull() {
// Arrange
HtmlHelper htmlHelper = new HtmlHelper(new ModelStateDictionary());
object text = null;
// Act
string encodedHtml = htmlHelper.Encode(text);
// Assert
Assert.AreEqual(String.Empty, encodedHtml);
}
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:11,代码来源:HtmlHelperTest.cs
示例16: TextAreaWithObjectAttributes
public void TextAreaWithObjectAttributes() {
// Arrange
ModelStateDictionary modelState = new ModelStateDictionary();
modelState.SetModelValue("foo", "foo-value");
HtmlHelper helper = new HtmlHelper(modelState);
// Act
var html = helper.TextArea("foo", new { attr = "value", cols = 6 });
// Assert
Assert.AreEqual(@"<textarea attr=""value"" cols=""6"" id=""foo"" name=""foo"" rows=""2"">foo-value</textarea>", html.ToHtmlString());
}
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:12,代码来源:TextAreaHelperTest.cs
示例17: ValidationMessageAllowsEmptyModelName
public void ValidationMessageAllowsEmptyModelName() {
// Arrange
ModelStateDictionary dictionary = new ModelStateDictionary();
dictionary.AddError("test", "some error text");
HtmlHelper htmlHelper = new HtmlHelper(dictionary);
// Act
var html = htmlHelper.ValidationMessage("test");
// Assert
Assert.AreEqual(@"<span class=""field-validation-error"">some error text</span>", html.ToHtmlString());
}
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:12,代码来源:ValidationHelperTest.cs
示例18: RadioButtonUsesModelStateToRemoveChecked
public void RadioButtonUsesModelStateToRemoveChecked() {
// Arrange
var modelState = new ModelStateDictionary();
modelState.SetModelValue("foo", "not-a-bar");
HtmlHelper helper = new HtmlHelper(modelState);
// Act
var html = helper.RadioButton("foo", "bar", new { @checked = "checked" } );
// Assert
Assert.AreEqual(@"<input id=""foo"" name=""foo"" type=""radio"" value=""bar"" />",
html.ToHtmlString());
}
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:13,代码来源:RadioButtonTest.cs
示例19: DropDownListWithAttributes
public void DropDownListWithAttributes() {
// Arrange
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act
var html = helper.DropDownList("foo", GetSelectList(), new { attr = "attr-val", attr2 = "attr-val2" });
// Assert
Assert.AreEqual(
@"<select attr=""attr-val"" attr2=""attr-val2"" id=""foo"" name=""foo"">
<option value=""A"">Alpha</option>
<option value=""B"">Bravo</option>
<option value=""C"">Charlie</option>
</select>",
html.ToHtmlString());
}
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:16,代码来源:SelectHelperTest.cs
示例20: DropDownListWithExplicitValue
public void DropDownListWithExplicitValue() {
// Arrange
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act
var html = helper.DropDownList("foo", null, GetSelectList(), "B", new Dictionary<string, object>{ {"attr", "attr-val"} });
// Assert
Assert.AreEqual(
@"<select attr=""attr-val"" id=""foo"" name=""foo"">
<option value=""A"">Alpha</option>
<option selected=""selected"" value=""B"">Bravo</option>
<option value=""C"">Charlie</option>
</select>",
html.ToHtmlString());
}
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:16,代码来源:SelectHelperTest.cs
注:本文中的System.Web.WebPages.Html.HtmlHelper类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论