我正在尝试显示一个包含我在后面的代码中创建的详细信息的列表。但是我在控制台中变得不确定。为什么会这样?
CS:
public partial class WebForm1 : System.Web.UI.Page
{
public List<Person> persons { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
Person p1 = new Person() { name = "Tom" };
Person p2 = new Person() { name = "Ed" };
List<Person> lijst = new List<Person>();
lijst.Add(p1);
lijst.Add(p2);
persons = lijst;
}
}
public class Person
{
public string name { get; set; }
}
aspx:
<script>
var persons = '<%= persons%>'
var length = persons.length;
for (var i = 0; i < length; i++) {
person = persons[i];
console.log(person.name);
}
</script>