/// <summary> /// Reads from view data. /// </summary> /// <param name="formViewModel">The field view model.</param> /// <param name="viewData">The view data.</param> private static void ReadFromViewData(FormViewModel formViewModel, ViewDataDictionary viewData) { Assert.ArgumentNotNull(formViewModel, nameof(formViewModel)); Assert.ArgumentNotNull(viewData, nameof(viewData)); for (int i = 0; i < formViewModel.Sections.Count; ++i) { var section = formViewModel.Sections[i]; for (int j = 0; j < section.Fields.Count; ++j) { var field = section.Fields[j]; string viewDataKey = $"{formViewModel.ClientId}.Sections[{i}].Fields[{j}].Value"; if (viewData.ModelState.ContainsKey(viewDataKey)) { var conditions = field.GetConditions(); if (!string.IsNullOrEmpty(conditions)) { RulesManager.RunRules(field.GetConditions(), new RuleContextModel(field, formViewModel, viewData.ModelState[viewDataKey])); } } } } }