public ActionResult Create(Field field) { if (ModelState.IsValid) { field.FieldName = field.FieldName.Replace(" ", "_"); //add a field to a database and save it context.Fields.Add(field); context.SaveChanges(); //create another field return RedirectToAction("Create"); } return View(field); }
//return a View to create a new form field along with a dropbox to select a field type // GET: /Fields/Create public ActionResult Create(int id) { ViewBag.UserTableId = id; Field f = new Field(); f.UserTableId = id; //create a list of items to be displayed in a dropdown box when creating new field List<SelectListItem> items = new List<SelectListItem>(); items.Add(new SelectListItem { Text = "Text", Value = "STRING", Selected = true }); items.Add(new SelectListItem { Text = "Numeric", Value = "INTEGER" }); items.Add(new SelectListItem { Text = "True/False", Value = "BOOL" }); //assign that list to a ViewBag so that it can be accessed from a View ViewBag.fieldTypes = items; //pass an empty form field to a View return View(f); }
public ActionResult Edit(Field field) { if (ModelState.IsValid) { context.Entry(field).State = EntityState.Modified; context.SaveChanges(); return RedirectToAction("Index"); } ViewBag.PossibleUserTables = context.UserTables; return View(field); }