public ActionResult Test() { string strXmlpath = Server.MapPath("~\\Models\\Location.xml"); var unit=from u in XDocument .Load (strXmlpath ).Document .Descendants ("Unit") select u; List<SelectListItem> lst = new List<SelectListItem>(); foreach (var u in unit) { if (u.Attribute("ID").Value == "2") { var city = u.Elements("city"); foreach (var c in city) lst.Add(new SelectListItem { Text = c.Attribute("Name").Value, Value = c.Attribute("ID").Value }); } } ViewData["cites"] = lst; var model = new UnitViewModel { Units = from units in XDocument.Load(strXmlpath).Document.Descendants("Unit") select new SelectListItem { Value = units.Attribute("ID").Value, Text = units.Attribute("Name").Value } }; List<SelectListItem> items = new List<SelectListItem>(); foreach (var v in model.Units) { items.Add(new SelectListItem { Text = v.Text, Value = v.Value }); } ViewData["xml"] = items; return View(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)