public ActionResult Index(MyStandardPage currentPage, MyFormData myFormData) { // Manipulate with the ModelState and/or do different stuff if items are valid or not var validatedItems = Validate(currentPage, myFormData); return(View(currentPage)); }
public ActionResult Index() { // We can initialize our form via the associated model var myData = new MyFormData { SomeValue = "3" }; return(View(myData)); }
public ActionResult Edit(int id) { MyFormData data = GetData(id); string initialData = JsonConvert.SerializeObject(data); ViewBag.formMetadataUrl = Url.RouteUrl("api", new { controller = "Home", action = "FormMetadata" }); return(View((object)initialData)); }
public ActionResult Index(MyFormData myData) { // We do (or initiate) our form data processing here // We can get the framework to do data validation for us, but that's beyond the scope of this example. Debug.WriteLine("Name = {0}, IsTrue = {1}, SomeValue = {2}", myData.Name, myData.IsTrue, myData.SomeValue); // Done... we choose to redirect to a new page. // In this example, we redirect back to ourself. This will call the Get method for our page (will have the appearance of resetting the form). var path = VirtualPathUtility.ToAbsolute("~/"); return(Redirect(path)); }
public ActionResult Load(int?id) { MyFormData data; if (id.HasValue) { data = GetData(id.Value); } else { data = new MyFormData(); } string initialData = JsonConvert.SerializeObject(data); return(Content(initialData, "application/json")); }
public ActionResult Save(MyFormData data) { IControlGroup fd = MyFormMetadata.GetMetadata(); MkoForms.Validators.ControlGroupValidator.Validate(data, fd); var r = new FormSaveReply(); if (data.lastName == "Fail") { r.isFailure = true; r.failureMessage = "Nie udało się zapisać zmian, błąd na żądanie użytkownika."; } else if (data.lastName == "Error") { r.isError = true; r.errors = new string[] { "Wartość jest niewystarczająca.", "Podane wartości są bez sensu!" }; r.propertyErrors = new Dictionary <string, object>(); r.propertyErrors["notifyViaMail"] = "In %s you must allow notifying by mail"; r.propertyErrors["extraPerson.lastName"] = "In %s the name seems suspicious."; r.propertyErrors["recipients.0"] = "W polu %s wartość jest brzydka."; r.propertyErrors["contacts.0.firstName"] = new string[] { "W polu %s mamy pierwszy błąd.", "W polu %s mamy też błąd kolejny" }; int lastIndex = data.contacts.Length - 1; string path = string.Format("contacts.{0}.lastName", lastIndex); r.propertyErrors[path] = "In %s we have an error added dynamically"; } else { r.isSuccess = true; } var rs = JsonConvert.SerializeObject(r, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); return(Content(rs, "application/json")); }
private static IList <bool> Validate(MyStandardPage currentPage, MyFormData model) { var validatedItems = new List <bool>(); if (currentPage.MainContentArea == null) { return(validatedItems); } var items = currentPage.MainContentArea.Items; foreach (var content in items) { var block = content.GetContent(); if (block == null) { continue; } var input = block as IDynamicField; if (input == null) { continue; } var validator = input.GetValidator(); if (validator == null) { continue; } validatedItems.Add(validator.IsValid(model, input.IsRequired)); } return(validatedItems); }