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


C# Html.HtmlHelper类代码示例

本文整理汇总了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");
        }
开发者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 &lt;1&gt;</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 &lt;1&gt;</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, "&lt;br /&gt;", "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


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