Exemplo n.º 1
0
 public ActionResult Index()
 {
     Contact contact = new Contact
     {
         Name = "张三",
         PhoneNo = "123456789",
         EmailAddress = "*****@*****.**"
     };
     return View(contact);
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
 public void Post(Contact contact)
 {
     Delete(contact.Id);
     contacts.Add(contact);
 }
Exemplo n.º 7
0
 public void Put(Contact contact)
 {
     contact.Id = Guid.NewGuid().ToString();
     contacts.Add(contact);
 }
Exemplo n.º 8
0
 public ActionResult Index(Contact contact)
 {
     return View("ModelState", this.ViewData.ModelState);
 }
Exemplo n.º 9
0
 public ActionResult Index(Contact contact)
 {
     return View("ValidationMessage", contact);
 }
Exemplo n.º 10
0
 public ActionResult Index(Contact contact)
 {
     return View(contact);
 }