显示xml提要asp.net C#

显示xml提要asp.net C#,c#,xml,asp.net-mvc,C#,Xml,Asp.net Mvc,这是我的xml文件: 这是我的模型: [XmlRoot(ElementName = "localteam")] public class Localteam { [XmlAttribute(AttributeName = "name")] public string Name { get; set; } [XmlAttribute(AttributeName = "goals")] public string Goals { get; set; } [X

这是我的xml文件:

这是我的模型:

[XmlRoot(ElementName = "localteam")]
public class Localteam
{
    [XmlAttribute(AttributeName = "name")]
    public string Name { get; set; }
    [XmlAttribute(AttributeName = "goals")]
    public string Goals { get; set; }
    [XmlAttribute(AttributeName = "id")]
    public string Id { get; set; }
}

this is my controller:

XmlDocument doc = new XmlDocument();

List<Localteam> s = new List<Localteam>();

doc.Load(Server.MapPath("soccer_inplay.xml"));

foreach (XmlNode node in doc.SelectNodes("/scores/category/"))
{
    s.Add(new Localteam
    {
        Name = node["Name"].InnerText          
    });
}

return View(s);
[XmlRoot(ElementName=“localteam”)]
公共类本地团队
{
[XmlAttribute(AttributeName=“name”)]
公共字符串名称{get;set;}
[XmlAttribute(AttributeName=“goals”)]
公共字符串目标{get;set;}
[XmlAttribute(AttributeName=“id”)]
公共字符串Id{get;set;}
}
这是我的控制器:
XmlDocument doc=新的XmlDocument();
列表s=新列表();
doc.Load(Server.MapPath(“soccer_inplay.xml”);
foreach(doc.SelectNodes(“/scores/category/”)中的XmlNode节点)
{
s、 添加(新本地团队)
{
名称=节点[“名称”]。InnerText
});
}
返回视图;
我的看法是:

<table>

    <tr>

        <th>Name</th>

        <th>Goals</th>

    </tr>

    @foreach (WebApplication22.Models.Localteam s in Model)

    {
        <tr>

            <td>@s.Name</td>

            <td>@s.Goals</td>

        </tr>

    }

</table>

名称
目标
@foreach(模型中的WebApplication22.Models.Localteam s)
{
@s、 名字
@s、 目标
}
我想显示这个xml提要,但是我不能,我在视图方面有问题

使用xml linq

using System.Collections.ObjectModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;



namespace ConsoleApplication57
{
    class Program
    {
        const string URL = "http://goalserve.com/samples/soccer_inplay.xml";
        static void Main(string[] args)
        {
            XDocument doc = XDocument.Load(URL);

            Localteam.teams = doc.Descendants("odd").Select(x => new Localteam()
            {
                Name = (string)x.Attribute("name"),
                games = x.Elements("type").Where(y => y.Attribute("id") != null).Select(y => new Game() {
                    id = (long)y.Attribute("id"),
                    opponent = (string)y.Attribute("name"),
                    suspend = (int)y.Attribute("suspend"),
                    odd = (Single)y.Attribute("odd"),
                    _type = (string)y.Attribute("type")
                }).ToList()
            }).ToList();
        }

    }
    public class Localteam
    {
        public static List<Localteam> teams = new List<Localteam>();

        public string Name { get; set; }
        public List<Game> games { get; set; }
    }
    public class Game
    {
        public string opponent { get; set; }
        public long id { get; set; }
        public int suspend { get; set; }
        public Single odd { get; set; }
        public string _type { get; set; }
    }
}
使用System.Collections.ObjectModel;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Xml;
使用System.Xml.Linq;
命名空间控制台应用程序57
{
班级计划
{
常量字符串URL=”http://goalserve.com/samples/soccer_inplay.xml";
静态void Main(字符串[]参数)
{
XDocument doc=XDocument.Load(URL);
Localteam.teams=doc.substands(“奇数”)。选择(x=>newlocalteam()
{
名称=(字符串)x.Attribute(“名称”),
games=x.Elements(“type”)。其中(y=>y.Attribute(“id”)!=null)。选择(y=>newgame(){
id=(长)y.Attribute(“id”),
对手=(字符串)y.Attribute(“名称”),
suspend=(int)y.Attribute(“suspend”),
奇数=(单个)y.属性(“奇数”),
_类型=(字符串)y.Attribute(“类型”)
})托利斯先生()
}).ToList();
}
}
公共类本地团队
{
公共静态列表团队=新列表();
公共字符串名称{get;set;}
公共列表游戏{get;set;}
}
公开课游戏
{
公共字符串对手{get;set;}
公共长id{get;set;}
公共int挂起{get;set;}
公共单奇数{get;set;}
公共字符串_type{get;set;}
}
}

我找到了,这不是问题所在。System.IO.DirectoryNotFoundException:找不到路径“c:\users\jt\documents\visual studio 2015\Projects\WebApplication22\WebApplication22\xml\soccer\u inplay.xml”的一部分。这是我的错误。但是soccer_inplay.xml在我的解决方案中,我无法显示它。视图必须与类一致。名字不对齐。你是想要一张每一条线上都有本地队和对手的单张桌子,还是想要一张单独的桌子?视图看起来像单个表,但对于每个本地团队,类看起来像不同的表。请修复视图,使其与xml结果匹配。