當前位置: 首頁>>代碼示例>>C#>>正文


C# HtmlHelper.GetUnobtrusiveValidationAttributes方法代碼示例

本文整理匯總了C#中System.HtmlHelper.GetUnobtrusiveValidationAttributes方法的典型用法代碼示例。如果您正苦於以下問題:C# HtmlHelper.GetUnobtrusiveValidationAttributes方法的具體用法?C# HtmlHelper.GetUnobtrusiveValidationAttributes怎麽用?C# HtmlHelper.GetUnobtrusiveValidationAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.HtmlHelper的用法示例。


在下文中一共展示了HtmlHelper.GetUnobtrusiveValidationAttributes方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetUnobtrusiveValidationAttributesMarksRenderedFieldsWithFullName

        public void GetUnobtrusiveValidationAttributesMarksRenderedFieldsWithFullName() {
            // Arrange
            var formContext = new FormContext();
            var viewContext = new Mock<ViewContext>();
            var viewData = new ViewDataDictionary();
            viewContext.SetupGet(vc => vc.FormContext).Returns(formContext);
            viewContext.SetupGet(vc => vc.ClientValidationEnabled).Returns(true);
            viewContext.SetupGet(vc => vc.UnobtrusiveJavaScriptEnabled).Returns(true);
            viewData.TemplateInfo.HtmlFieldPrefix = "Prefix";
            var viewDataContainer = MvcHelper.GetViewDataContainer(viewData);
            var htmlHelper = new HtmlHelper(viewContext.Object, viewDataContainer);

            // Act
            htmlHelper.GetUnobtrusiveValidationAttributes("foobar");

            // Assert
            Assert.IsFalse(formContext.RenderedField("foobar"));
            Assert.IsTrue(formContext.RenderedField("Prefix.foobar"));
        }
開發者ID:adrianvallejo,項目名稱:MVC3_Source,代碼行數:19,代碼來源:HtmlHelperTest.cs

示例2: AssertBadClientValidationRule

        // Helpers

        private static void AssertBadClientValidationRule(HtmlHelper htmlHelper, string expectedMessage, params ModelClientValidationRule[] rules) {
            htmlHelper.ClientValidationRuleFactory = delegate { return rules; };
            ExceptionHelper.ExpectInvalidOperationException(
                () => htmlHelper.GetUnobtrusiveValidationAttributes(Guid.NewGuid().ToString()),
                expectedMessage
            );
        }
開發者ID:adrianvallejo,項目名稱:MVC3_Source,代碼行數:9,代碼來源:HtmlHelperTest.cs

示例3: GetUnobtrusiveValidationAttributesUsesShortNameForModelMetadataLookup

        public void GetUnobtrusiveValidationAttributesUsesShortNameForModelMetadataLookup() {
            // Arrange
            string passedName = null;
            var formContext = new FormContext();
            var viewContext = new Mock<ViewContext>();
            var viewData = new ViewDataDictionary();
            viewContext.SetupGet(vc => vc.FormContext).Returns(formContext);
            viewContext.SetupGet(vc => vc.ClientValidationEnabled).Returns(true);
            viewContext.SetupGet(vc => vc.UnobtrusiveJavaScriptEnabled).Returns(true);
            viewData.TemplateInfo.HtmlFieldPrefix = "Prefix";
            var viewDataContainer = MvcHelper.GetViewDataContainer(viewData);
            var htmlHelper = new HtmlHelper(viewContext.Object, viewDataContainer);
            htmlHelper.ClientValidationRuleFactory = (name, _) => {
                passedName = name;
                return Enumerable.Empty<ModelClientValidationRule>();
            };

            // Act
            htmlHelper.GetUnobtrusiveValidationAttributes("foobar");

            // Assert
            Assert.AreEqual("foobar", passedName);
        }
開發者ID:adrianvallejo,項目名稱:MVC3_Source,代碼行數:23,代碼來源:HtmlHelperTest.cs

示例4: GetUnobtrusiveValidationAttributeUsesViewDataForModelMetadataLookup

        public void GetUnobtrusiveValidationAttributeUsesViewDataForModelMetadataLookup() {
            // Arrange
            var formContext = new FormContext();
            var viewContext = new Mock<ViewContext>();
            var viewData = new ViewDataDictionary<MyModel>();
            viewContext.SetupGet(vc => vc.FormContext).Returns(formContext);
            viewContext.SetupGet(vc => vc.ClientValidationEnabled).Returns(true);
            viewContext.SetupGet(vc => vc.UnobtrusiveJavaScriptEnabled).Returns(true);
            viewData.TemplateInfo.HtmlFieldPrefix = "Prefix";
            var viewDataContainer = MvcHelper.GetViewDataContainer(viewData);
            var htmlHelper = new HtmlHelper(viewContext.Object, viewDataContainer);

            // Act
            IDictionary<string, object> result = htmlHelper.GetUnobtrusiveValidationAttributes("MyProperty");

            // Assert
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual("true", result["data-val"]);
            Assert.AreEqual("My required message", result["data-val-required"]);
        }
開發者ID:adrianvallejo,項目名稱:MVC3_Source,代碼行數:20,代碼來源:HtmlHelperTest.cs

示例5: GetUnobtrusiveValidationAttributesWithTwoClientRules

        public void GetUnobtrusiveValidationAttributesWithTwoClientRules() {
            // Arrange
            var formContext = new FormContext();
            var viewContext = new Mock<ViewContext>();
            viewContext.SetupGet(vc => vc.FormContext).Returns(formContext);
            viewContext.SetupGet(vc => vc.ClientValidationEnabled).Returns(true);
            viewContext.SetupGet(vc => vc.UnobtrusiveJavaScriptEnabled).Returns(true);
            var viewDataContainer = MvcHelper.GetViewDataContainer(new ViewDataDictionary());
            var htmlHelper = new HtmlHelper(viewContext.Object, viewDataContainer);
            htmlHelper.ClientValidationRuleFactory = delegate {
                ModelClientValidationRule rule1 = new ModelClientValidationRule { ValidationType = "type", ErrorMessage = "error" };
                rule1.ValidationParameters["foo"] = "bar";
                rule1.ValidationParameters["baz"] = "biff";
                ModelClientValidationRule rule2 = new ModelClientValidationRule { ValidationType = "othertype", ErrorMessage = "othererror" };
                rule2.ValidationParameters["true3"] = "false4";
                return new[] { rule1, rule2 };
            };

            // Act
            IDictionary<string, object> result = htmlHelper.GetUnobtrusiveValidationAttributes("foobar");

            // Assert
            Assert.AreEqual("error", result["data-val-type"]);
            Assert.AreEqual("bar", result["data-val-type-foo"]);
            Assert.AreEqual("biff", result["data-val-type-baz"]);
            Assert.AreEqual("othererror", result["data-val-othertype"]);
            Assert.AreEqual("false4", result["data-val-othertype-true3"]);
        }
開發者ID:adrianvallejo,項目名稱:MVC3_Source,代碼行數:28,代碼來源:HtmlHelperTest.cs

示例6: GetUnobtrusiveValidationAttributesMessageIsHtmlEncoded

        public void GetUnobtrusiveValidationAttributesMessageIsHtmlEncoded() {
            // Arrange
            var formContext = new FormContext();
            var viewContext = new Mock<ViewContext>();
            viewContext.SetupGet(vc => vc.FormContext).Returns(formContext);
            viewContext.SetupGet(vc => vc.ClientValidationEnabled).Returns(true);
            viewContext.SetupGet(vc => vc.UnobtrusiveJavaScriptEnabled).Returns(true);
            var viewDataContainer = MvcHelper.GetViewDataContainer(new ViewDataDictionary());
            var htmlHelper = new HtmlHelper(viewContext.Object, viewDataContainer);
            htmlHelper.ClientValidationRuleFactory = delegate {
                return new[] { new ModelClientValidationRule { ValidationType = "type", ErrorMessage = "<script>alert('xss')</script>" } };
            };

            // Act
            IDictionary<string, object> result = htmlHelper.GetUnobtrusiveValidationAttributes("foobar");

            // Assert
            Assert.AreEqual("&lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;", result["data-val-type"]);
        }
開發者ID:adrianvallejo,項目名稱:MVC3_Source,代碼行數:19,代碼來源:HtmlHelperTest.cs

示例7: GetUnobtrusiveValidationAttributesIncludesDataValTrueWithNonEmptyClientRuleList

        public void GetUnobtrusiveValidationAttributesIncludesDataValTrueWithNonEmptyClientRuleList() {
            // Arrange
            var formContext = new FormContext();
            var viewContext = new Mock<ViewContext>();
            viewContext.SetupGet(vc => vc.FormContext).Returns(formContext);
            viewContext.SetupGet(vc => vc.ClientValidationEnabled).Returns(true);
            viewContext.SetupGet(vc => vc.UnobtrusiveJavaScriptEnabled).Returns(true);
            var viewDataContainer = MvcHelper.GetViewDataContainer(new ViewDataDictionary());
            var htmlHelper = new HtmlHelper(viewContext.Object, viewDataContainer);
            htmlHelper.ClientValidationRuleFactory = delegate {
                return new[] { new ModelClientValidationRule { ValidationType = "type" } };
            };

            // Act
            IDictionary<string, object> result = htmlHelper.GetUnobtrusiveValidationAttributes("foobar");

            // Assert
            Assert.AreEqual("true", result["data-val"]);
        }
開發者ID:adrianvallejo,項目名稱:MVC3_Source,代碼行數:19,代碼來源:HtmlHelperTest.cs

示例8: GetUnobtrusiveValidationAttributesReturnsEmptySetAndSetsFieldAsRenderedForFieldWithNoClientRules

        public void GetUnobtrusiveValidationAttributesReturnsEmptySetAndSetsFieldAsRenderedForFieldWithNoClientRules() {
            // Arrange
            var formContext = new FormContext();
            var viewContext = new Mock<ViewContext>();
            viewContext.SetupGet(vc => vc.FormContext).Returns(formContext);
            viewContext.SetupGet(vc => vc.ClientValidationEnabled).Returns(true);
            viewContext.SetupGet(vc => vc.UnobtrusiveJavaScriptEnabled).Returns(true);
            var viewDataContainer = MvcHelper.GetViewDataContainer(new ViewDataDictionary());
            var htmlHelper = new HtmlHelper(viewContext.Object, viewDataContainer);
            htmlHelper.ClientValidationRuleFactory = delegate { return Enumerable.Empty<ModelClientValidationRule>(); };

            // Act
            IDictionary<string, object> result = htmlHelper.GetUnobtrusiveValidationAttributes("foobar");

            // Assert
            Assert.AreEqual(0, result.Count);
            Assert.IsTrue(formContext.RenderedField("foobar"));
        }
開發者ID:adrianvallejo,項目名稱:MVC3_Source,代碼行數:18,代碼來源:HtmlHelperTest.cs

示例9: GetUnobtrusiveValidationAttributesReturnsEmptySetWhenFieldHasAlreadyBeenRendered

        public void GetUnobtrusiveValidationAttributesReturnsEmptySetWhenFieldHasAlreadyBeenRendered() {
            // Arrange
            var formContext = new FormContext();
            formContext.RenderedField("foobar", true);
            var viewContext = new Mock<ViewContext>();
            viewContext.SetupGet(vc => vc.FormContext).Returns(formContext);
            viewContext.SetupGet(vc => vc.ClientValidationEnabled).Returns(true);
            viewContext.SetupGet(vc => vc.UnobtrusiveJavaScriptEnabled).Returns(true);
            var viewDataContainer = MvcHelper.GetViewDataContainer(new ViewDataDictionary());
            var htmlHelper = new HtmlHelper(viewContext.Object, viewDataContainer);

            // Act
            IDictionary<string, object> result = htmlHelper.GetUnobtrusiveValidationAttributes("foobar");

            // Assert
            Assert.AreEqual(0, result.Count);
        }
開發者ID:adrianvallejo,項目名稱:MVC3_Source,代碼行數:17,代碼來源:HtmlHelperTest.cs


注:本文中的System.HtmlHelper.GetUnobtrusiveValidationAttributes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。