2013-04-10 53 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