• MVC 子对象数据传递


     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>
  • 相关阅读:
    局部类
    内部类
    程序的异常
    四种修饰符
    接口之间的多继承
    多态
    继承父类并实现多个接口
    接口内容小结
    接口的静态方法和私有方法
    顺序栈与链式栈
  • 原文地址:https://www.cnblogs.com/liuxiaoji/p/4748725.html
Copyright © 2020-2023  润新知