1、接受参数
1 public ActionResult Address(User user) 2 { 3 return View(); 4 }
2. User对象类型
1 public class User 2 { 3 public string Name { get; set; } 4 5 /// <summary> 6 /// 子对象(单个) 7 /// </summary> 8 public Address Address { get; set; } 9 10 /// <summary> 11 /// 子对象(集合) 12 /// </summary> 13 public List<Nick> Nicks { get; set; } 14 } 15 16 public class Address 17 { 18 public string City { get; set; } 19 20 public string Email { get; set; } 21 } 22 23 public class Nick { 24 public string Name { get; set; } 25 }
3.页面传参
@*错误的传参*@ <a href="@Url.Action("Address", new MvcApplication.Models.User { Name ="小", Address = new MvcApplication.Models.Address { City ="成都", Email="4444441@qq.com" } })">点击测试1</a> <br /> @*正确的url传参*@ <a href="/Home/Address?Name=小&Address.Email=11&Nicks[0].Name=测试">点击测试2</a> @*正确的表单提交*@ <form action="/Home/Address" method="get"> <input type="hidden" name="Name" value="小" /> <input type="hidden" name="Address.Email" value="11" /> <input type="hidden" name="Nicks[0].Name" value="测试" /> <input type="submit" value="测试3"/> </form>