public ActionResult Index() { Contact contact = new Contact { Name = "张三", PhoneNo = "123456789", EmailAddress = "*****@*****.**" }; return View(contact); }
public ActionResult DemoAction(Contact foo, Contact bar) { Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("foo.Name", foo.Name); parameters.Add("foo.PhoneNo", foo.PhoneNo); parameters.Add("foo.EmailAddress", foo.EmailAddress); Address address = foo.Address; parameters.Add("foo.Address", string.Format("{0}省{1}市{2}{3}", address.Province, address.City, address.District, address.Street)); parameters.Add("bar.Name", bar.Name); parameters.Add("bar.PhoneNo", bar.PhoneNo); parameters.Add("bar.EmailAddress", bar.EmailAddress); address = bar.Address; parameters.Add("bar.Address", string.Format("{0}省{1}市{2}{3}", address.Province, address.City, address.District, address.Street)); return View("DemoAction", parameters); }
public ActionResult Index() { Address address = new Address { Province = "江苏", City = "苏州", District = "工业园区", Street = "星湖街328号" }; Contact contact = new Contact { Name = "张三", PhoneNo = "123456789", EmailAddress = "*****@*****.**", Address = address }; return View(contact); }
public ActionResult DemoAction(Contact[] contacts) { Dictionary<string, object> parameters = new Dictionary<string, object>(); for (int i = 0; i < contacts.Length; i++) { string name = contacts[i].Name; string phoneNo = contacts[i].PhoneNo; string emailAddress = contacts[i].EmailAddress; string address = string.Format("{0}省{1}市{2}{3}", contacts[i].Address.Province, contacts[i].Address.City, contacts[i].Address.District, contacts[i].Address.Street); parameters.Add(string.Format("[{0}].Name", i), name); parameters.Add(string.Format("[{0}].PhoneNo", i), phoneNo); parameters.Add(string.Format("[{0}].EmailAddress", i), emailAddress); parameters.Add(string.Format("[{0}].Address", i), address); } return View("DemoAction", parameters); }
public ActionResult Index() { Address address = new Address { Province = "江苏", City = "苏州", District = "工业园区", Street = "星湖街328号" }; Contact contact = new Contact { Name = "张三", PhoneNo = "123456789", EmailAddress = "*****@*****.**", Address = address }; ModelMetadata metadata = ModelMetadataProviders.Current.GetMetadataForType(() => contact, typeof(Contact)); ModelValidator validator = ModelValidator.GetModelValidator(metadata,ControllerContext); return View(validator.Validate(contact)); }
public void Post(Contact contact) { Delete(contact.Id); contacts.Add(contact); }
public void Put(Contact contact) { contact.Id = Guid.NewGuid().ToString(); contacts.Add(contact); }
public ActionResult Index(Contact contact) { return View("ModelState", this.ViewData.ModelState); }
public ActionResult Index(Contact contact) { return View("ValidationMessage", contact); }
public ActionResult Index(Contact contact) { return View(contact); }