2014-02-26 49 views
0

我有困難的時候嘗試正確地獲取我的模型,是否有無論如何我可以適應IEnumerable內的2個模型?這是我有..IEnumerable內的2個模型

public class threadreplying 
{ 

    public IEnumerable<profile,Threadpost> IEThreadpost { get; set; } 
    public taker orginalthread { get; set; } 


} 

該IEnumerable只需要1個參數如何使IEthreadpost工作?我這樣做是因爲我在我的sql中實現了一個Join,並要求來自這兩個模型的信息存儲在數據庫中。我也試圖做到這一點

public class ModelMix 
{ 
    public profile profiles { get; set; } 
    public Threadpost threadposts { get; set; } 
} 

public class threadreplying 
{ 

    public IEnumerable<ModelMix> IEThreadpost { get; set; } 
    public taker orginalthread { get; set; } 


} 

這工作,但它並沒有它給了我一個空的錯誤觀點裏面工作eventhough我檢查針對

@if (Model.IEThreadpost != null) 
{ 
    foreach (var item in Model.IEThreadpost) 
    { 
     @item.threadposts.post 
    } 
    } 
+0

您正在收到錯誤,因爲threadposts屬性爲空。 – Maess

回答

0

您需要檢查@item.threadposts爲空。

@if (Model.IEThreadpost != null) 
{ 
    foreach (var item in Model.IEThreadpost) 
    { 
     @if (item.threadposts != null) 
     { 
      @item.threadposts.post 
     } 
    } 
} 

當然,你應該認識到提前做什麼該檢查含義是,你應該確保這是不是你以前的邏輯,你實際上做你select的指示。

相關問題