本文整理汇总了C#中System.Web.WebPages.Html.HtmlHelper.CheckBox方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.CheckBox方法的具体用法?C# HtmlHelper.CheckBox怎么用?C# HtmlHelper.CheckBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.WebPages.Html.HtmlHelper
的用法示例。
在下文中一共展示了HtmlHelper.CheckBox方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckboxWithEmptyNameThrows
public void CheckboxWithEmptyNameThrows() {
// Arrange
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act and assert
ExceptionAssert.ThrowsArgNullOrEmpty(() => helper.CheckBox(null), "name");
ExceptionAssert.ThrowsArgNullOrEmpty(() => helper.CheckBox(String.Empty), "name");
}
示例2: CheckboxWithExplicitChecked
public void CheckboxWithExplicitChecked() {
// Arrange
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act
var html = helper.CheckBox("foo", true);
// Assert
Assert.AreEqual(@"<input checked=""checked"" id=""foo"" name=""foo"" type=""checkbox"" />",
html.ToHtmlString());
}
示例3: CheckboxWithDictionaryAttributes
public void CheckboxWithDictionaryAttributes() {
// Arrange
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act
var html = helper.CheckBox("foo", new Dictionary<string, object> { { "attr", "attr-value" } });
// Assert
Assert.AreEqual(@"<input attr=""attr-value"" id=""foo"" name=""foo"" type=""checkbox"" />",
html.ToHtmlString());
}
示例4: CheckboxWithDefaultArguments
public void CheckboxWithDefaultArguments() {
// Arrange
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act
var html = helper.CheckBox("foo");
// Assert
Assert.AreEqual(@"<input id=""foo"" name=""foo"" type=""checkbox"" />",
html.ToHtmlString());
}
示例5: CheckboxWithModelValue
public void CheckboxWithModelValue() {
// Arrange
var modelState = new ModelStateDictionary();
modelState.SetModelValue("foo", true);
HtmlHelper helper = new HtmlHelper(modelState);
// Act
var html = helper.CheckBox("foo");
// Assert
Assert.AreEqual(@"<input checked=""checked"" id=""foo"" name=""foo"" type=""checkbox"" />",
html.ToHtmlString());
}
示例6: CheckboxWithNonBooleanModelValue
public void CheckboxWithNonBooleanModelValue() {
// Arrange
var modelState = new ModelStateDictionary();
modelState.SetModelValue("foo", Boolean.TrueString);
HtmlHelper helper = new HtmlHelper(modelState);
// Act
var html = helper.CheckBox("foo");
// Assert
Assert.AreEqual(@"<input checked=""checked"" id=""foo"" name=""foo"" type=""checkbox"" />",
html.ToHtmlString());
modelState.SetModelValue("foo", new object());
helper = new HtmlHelper(modelState);
// Act and Assert
ExceptionAssert.Throws<InvalidOperationException>(() => helper.CheckBox("foo"),
"The parameter conversion from type \"System.Object\" to type \"System.Boolean\" failed because no " +
"type converter can convert between these types.");
}
示例7: CheckBoxOverwritesImplicitAttributes
public void CheckBoxOverwritesImplicitAttributes() {
// Arrange
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act
var html = helper.CheckBox("foo", true, new { type = "fooType", name = "bar" });
// Assert
Assert.AreEqual(@"<input checked=""checked"" id=""foo"" name=""foo"" type=""fooType"" />",
html.ToHtmlString());
}
示例8: CheckBoxUsesCustomErrorClass
//[TestMethod]
// Can't test as it sets a static property
// Review: Need to redo test once we fix set once property
public void CheckBoxUsesCustomErrorClass() {
// Arrange
var modelState = new ModelStateDictionary();
modelState.AddError("foo", "error");
HtmlHelper.ValidationInputCssClassName = "my-error-class";
HtmlHelper helper = new HtmlHelper(modelState);
// Act
var html = helper.CheckBox("foo", true, new { @class = "my-class" });
// Assert
Assert.AreEqual(@"<input checked=""checked"" class=""my-error-class my-class"" id=""foo"" name=""foo"" type=""checkbox"" />",
html.ToHtmlString());
}
示例9: CheckBoxWithModelStateCheckedOverwritesHtmlAttribute
public void CheckBoxWithModelStateCheckedOverwritesHtmlAttribute() {
// Arrange
var modelState = new ModelStateDictionary();
modelState.SetModelValue("foo", false);
HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
// Act
var html = helper.CheckBox("foo", false, new { @checked = "checked" });
// Assert
Assert.AreEqual(@"<input id=""foo"" name=""foo"" type=""checkbox"" />",
html.ToHtmlString());
}