再谈Jquery Ajax方法传递到action(补充)

2020-05-23 06:07:41易采站长站整理

之前写过一篇文章Jquery Ajax方法传值到action,本文是对该文的补充
假设 controller中的方法是如下:



public ActionResult ReadPerson(PersonModel model) 
        { 
            string s = model.ToString(); 
            return Content(s); 
        }


public ActionResult ReadPersons(List<PersonModel> model) 
        { 
            string result = “”; 
            if (model == null) return Content(result); 
            foreach (var s in model) 
            { 
                result += s.ToString(); 
                result += “————-“; 
            }
            return Content(result); 
        }


其中PersonModel定义如下:



public class PersonModel 
    { 
        public int id 
        { 
            set; 
            get; 
        } 
        public string name 
        { 
            set; 
            get; 
        }


        public int age 
        { 
            set; 
            get; 
        }


        public bool gender 
        { 
            set; 
            get; 
        }