2013-10-01 16 views
0

我有一個View其包含一個ICollection其中包含一組文件名。爲視圖過濾ICollection的最佳做法?

我在View上有幾個區域,我想列出這些文件名。但是,根據View的區域,我只想要列出某些類型的文件。

過濾ICollection的最佳做法是什麼?我應該在Controller上過濾它,然後將它傳遞給View或者我可以在View上過濾嗎?

回答

1

我認爲最好的做法是在模型視圖包含列出了各個領域

class ViewModel 
{ 
    ICollection<string> ForArea1ExampleNames{get;set;} 
    ICollection<string> ForArea2ExampleNames{get;set;} 

    public ViewModel(ICollection<string> forArea1ExampleNames,ICollection<string> forArea2ExampleNames) 
    { 
     ForArea1ExampleNames = forArea1ExampleNames; 
     ForArea2ExampleNames = forArea2ExampleNames; 
    } 

} 

在控制器

var forArea1ExampleNames = SomeService.GetForArea1ExampleNames()//This is 
var forArea2ExampleNames = SomeService.GetForArea2ExampleNames()// business logic 
var model = new ViewModel(forArea1ExampleNames,forArea2ExampleNames); 

過濾的文件名,是企業logic.So應該分開