本文整理汇总了C#中System.Web.WebPages.Html.HtmlHelper类的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper类的具体用法?C# HtmlHelper怎么用?C# HtmlHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HtmlHelper类属于System.Web.WebPages.Html命名空间,在下文中一共展示了HtmlHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
}
示例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");
}
示例3: ValidationMessageWithNoErrorResultsInNullString
public void ValidationMessageWithNoErrorResultsInNullString() {
// Arrange
HtmlHelper htmlHelper = new HtmlHelper(new ModelStateDictionary());
// Act
var html = htmlHelper.ValidationMessage("does-not-exist");
Assert.IsNull(html);
}
示例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());
}
示例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.");
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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.");
}
示例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());
}
示例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());
}
示例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);
}
示例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.");
}
示例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);
}