Asp.net mvc 4 mvc视图中的多个循环

Asp.net mvc 4 mvc视图中的多个循环,asp.net-mvc-4,Asp.net Mvc 4,如果我有下面的代码,那么在一个视图上有两个视图数据是可能的吗? 我该怎么做呢 非常感谢 赫斯 多一点代码会有所帮助。但假设您的Tble_内容具有如下结构: public class Tble_content { public int Id {get;set;} public string Content{get;set;} } public class ContentViewModel { public string ContentPage {get;set;}

如果我有下面的代码,那么在一个视图上有两个视图数据是可能的吗? 我该怎么做呢 非常感谢 赫斯


多一点代码会有所帮助。但假设您的
Tble_内容
具有如下结构:

public class Tble_content {
    public int Id {get;set;}
    public string Content{get;set;}
}
public class ContentViewModel {
    public string ContentPage {get;set;}
    public string ContentList {get;set;}
}
public ActionResult Index(long id = 0)
{
    var contentPage = (from c in db.Tble_content
                        where c.id == id
                        select c);
    var contentlist = (from c in db.Tble_content
                                where c.EN_TopPageID == id
                                select c);

    return View(new ContentViewModel {
       ContentPage = contentPage,
       ContentList = contentlist
    });
}
您可以使用如下所示的viewmodel:

public class Tble_content {
    public int Id {get;set;}
    public string Content{get;set;}
}
public class ContentViewModel {
    public string ContentPage {get;set;}
    public string ContentList {get;set;}
}
public ActionResult Index(long id = 0)
{
    var contentPage = (from c in db.Tble_content
                        where c.id == id
                        select c);
    var contentlist = (from c in db.Tble_content
                                where c.EN_TopPageID == id
                                select c);

    return View(new ContentViewModel {
       ContentPage = contentPage,
       ContentList = contentlist
    });
}
然后将其传递给如下视图:

public class Tble_content {
    public int Id {get;set;}
    public string Content{get;set;}
}
public class ContentViewModel {
    public string ContentPage {get;set;}
    public string ContentList {get;set;}
}
public ActionResult Index(long id = 0)
{
    var contentPage = (from c in db.Tble_content
                        where c.id == id
                        select c);
    var contentlist = (from c in db.Tble_content
                                where c.EN_TopPageID == id
                                select c);

    return View(new ContentViewModel {
       ContentPage = contentPage,
       ContentList = contentlist
    });
}

冯:很抱歉,这是我需要的,让它工作非常感谢你的帮助,赫斯