当前位置: 首页>>代码示例>>C#>>正文


C# HtmlHelper.CheckBox方法代码示例

本文整理汇总了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");
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:8,代码来源:CheckBoxTest.cs

示例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());
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:11,代码来源:CheckBoxTest.cs

示例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());
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:11,代码来源:CheckBoxTest.cs

示例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());
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:11,代码来源:CheckBoxTest.cs

示例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());
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:13,代码来源:CheckBoxTest.cs

示例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.");
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:22,代码来源:CheckBoxTest.cs

示例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());
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:11,代码来源:CheckBoxTest.cs

示例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());
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:17,代码来源:CheckBoxTest.cs

示例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());
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:13,代码来源:CheckBoxTest.cs


注:本文中的System.Web.WebPages.Html.HtmlHelper.CheckBox方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。