I am trying to get sorting working for certain columns from an xml file. Here is what I have.
public ActionResult Index(string sortOrder)
{
IEnumerable<Personal> personals;
XmlDocument doc = new XmlDocument();
List<Personal> persons = new List<Personal>();
doc.Load("C:\\Users\\Matt.Dodson\\Desktop\\SampleWork\\PersonsApplicationFromXMLFile\\PersonsApplicationFromXMLFile\\DAL\\Personal.xml");
foreach (XmlNode node in doc.SelectNodes("/Persons/record"))
{
persons.Add(new Personal
{
ID = node["ID"].InnerText,
Name = node["Name"].InnerText,
Email = node["Email"].InnerText,
DateOfBirth = node["DateOfBirth"].InnerText,
Gender = node["Gender"].InnerText,
City = node["City"].InnerText
});
}
switch (sortOrder)
{
case "ID":
personals = persons.OrderBy(Personal => Personal.ID);
break;
case "Name":
personals = persons.OrderBy(Personal => Personal.Name);
break;
case "City":
personals = persons.OrderBy(Personal => Personal.City);
break;
default:
break;
}
return View(persons);
}
Things I've tried include .getElementByTagName("ID").toString().OrderBy(...), to no avail. I'm pretty sure I've got syntax all wrong. Please help and thank you.