在学习 MVC/C# 时,将 xml 数据序列化为模型然后将其呈现(绑定)到视图中的最有效方法是什么?
我有以下
public static MovieSummary Deserialize()
{
XmlSerializer serializer = new XmlSerializer(typeof(MovieSummary));
TextReader textReader;
textReader = new StreamReader("c:\\movies.xml");
MovieSummary summary = (MovieSummary)serializer.Deserialize(textReader);
textReader.Close();
return summary;
}
public class MovieSummary
{
public List<Movie> Movies { get; set; }
}
public class Movie
{
public int id { get; set; }
public string name { get; set; }
}
<?xml version="1.0" encoding="utf-8"?>
<movies>
<movie>
<id>1</id>
<name>The Dark Knight</name>
</movie>
<movie>
<id>2</id>
<name>Iron Man</name>
</movie>
</movies>
我想调用反序列化函数并使用摘要。控制器的代码如何查找 public ActionResult ListMovies()?