2013-04-10 20 views
0

如果我有下面的代码,有可能在一个视图上有两个视图数据? 我怎么会去提前 碎甲弹在一个视图中的多个循环mvc

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(); 
    } 

回答

1

多一点的代码,将有助于这样做 非常感谢。不过,假设你的Tble_content具有这样的结构:

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 
    }); 
} 
+0

冯 对不起,小代码,但这是我需要得到它的工作 非常感谢您的帮助 Hesh – hesh 2013-04-10 11:32:57

+0

你是欢迎。 – 2013-04-10 12:13:30