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


C# FormContext.GetJsonValidationMetadata方法代码示例

本文整理汇总了C#中FormContext.GetJsonValidationMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# FormContext.GetJsonValidationMetadata方法的具体用法?C# FormContext.GetJsonValidationMetadata怎么用?C# FormContext.GetJsonValidationMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FormContext的用法示例。


在下文中一共展示了FormContext.GetJsonValidationMetadata方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetJsonValidationMetadata_ValidationSummary

        public void GetJsonValidationMetadata_ValidationSummary()
        {
            // Arrange
            FormContext context = new FormContext() { FormId = "theFormId", ValidationSummaryId = "validationSummary" };

            ModelClientValidationRule rule = new ModelClientValidationRule() { ValidationType = "ValidationType1", ErrorMessage = "Error Message" };
            rule.ValidationParameters["theParam"] = new { FirstName = "John", LastName = "Doe", Age = 32 };
            FieldValidationMetadata metadata = new FieldValidationMetadata() { FieldName = "theFieldName", ValidationMessageId = "theFieldName_ValidationMessage" };
            metadata.ValidationRules.Add(rule);
            context.FieldValidators["theFieldName"] = metadata;

            // Act
            string jsonMetadata = context.GetJsonValidationMetadata();

            // Assert
            string expected = @"{""Fields"":[{""FieldName"":""theFieldName"",""ReplaceValidationMessageContents"":false,""ValidationMessageId"":""theFieldName_ValidationMessage"",""ValidationRules"":[{""ErrorMessage"":""Error Message"",""ValidationParameters"":{""theParam"":{""FirstName"":""John"",""LastName"":""Doe"",""Age"":32}},""ValidationType"":""ValidationType1""}]}],""FormId"":""theFormId"",""ReplaceValidationSummary"":false,""ValidationSummaryId"":""validationSummary""}";
            Assert.Equal(expected, jsonMetadata);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:18,代码来源:FormContextTest.cs

示例2: OutputClientValidation

        private static void OutputClientValidation(HttpResponseBase response, FormContext formContext) {
            if (!formContext.ClientValidationEnabled) {
                return; // do nothing
            }

            // output a call that resembles:
            // _clientValidationFunction(validationObject, userContext);

            string validationJson = formContext.GetJsonValidationMetadata();

            string userContextJson = (formContext.ClientValidationState != null)
                ? new JavaScriptSerializer().Serialize(formContext.ClientValidationState)
                : "null";

            string scriptWithCorrectNewLines = _clientValidationScript.Replace("\r\n", Environment.NewLine);
            string formatted = String.Format(CultureInfo.InvariantCulture, scriptWithCorrectNewLines,
                formContext.ClientValidationFunction, validationJson, userContextJson);

            response.Write(formatted);
        }
开发者ID:Marceli,项目名称:JQueryGridTest,代码行数:20,代码来源:MvcForm.cs


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