如何将值从实体层传递到表示层。我已经填充了对象 Person,但是当我在 Presentation 中调用它时它变为空。
谁能帮我。提前致谢!
实体:
public class Person
{
public int PersonID { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
}
数据层:
public List<Person> GetPersonSingleByPersonID(string personID)
{
List<Person> objPerson = new List<Person>();
DataTable dt = new DataTable();
...
foreach (DataRow dr in dt.Rows)
{
objPerson.Add(new Person()
{
PersonID = dr["PersonID"].ToString(),
Firstname = dr["Firstname"].ToString(),
Lastname = dr["Lastname"].ToString()
});
}
return objPerson;
}
表示层:
Person objPerson = new Person(); //I think error goes here
txtPersonID.Text = objPerson.PersonID;
txtFirstname.Text = objPerson.Firstname;
txtLastname.Text = objPerson.Lastname;