public IEnumerable<SelectListItem> GetProvince(){ XDocument xDoc = XDocument.Load(System.Web.HttpContext.Current.Server.MapPath("~/Models/Area.xml")); IEnumerable<SelectListItem> province = from p in xDoc.Descendants("area") select new SelectListItem {Text = p.Element("province").Value,Value = p.Element("provinceID").Value, }; return province;}報錯,未將對象引用到實例。這是為什么呢,高人指點,謝謝了
2 回答

慕斯王
TA貢獻1864條經驗 獲得超2個贊
public IEnumerable<SelectListItem> GetProvince()
{
XDocument xDoc = XDocument.Load(System.Web.HttpContext.Current.Server.MapPath("~/Models/Area.xml"));
return from p in xDoc.Descendants("area")
select new SelectListItem
{
Text = p.Element("province").Value,
Value = p.Element("provinceID").Value,
};
}
說實話,你的問題我不清楚是什么原因.不過你為什么不直接返回值了.
- 2 回答
- 0 關注
- 767 瀏覽
添加回答
舉報
0/150
提交
取消