0
我有一個View
其包含一個ICollection
其中包含一組文件名。爲視圖過濾ICollection的最佳做法?
我在View
上有幾個區域,我想列出這些文件名。但是,根據View
的區域,我只想要列出某些類型的文件。
過濾ICollection的最佳做法是什麼?我應該在Controller
上過濾它,然後將它傳遞給View
或者我可以在View
上過濾嗎?
我有一個View
其包含一個ICollection
其中包含一組文件名。爲視圖過濾ICollection的最佳做法?
我在View
上有幾個區域,我想列出這些文件名。但是,根據View
的區域,我只想要列出某些類型的文件。
過濾ICollection的最佳做法是什麼?我應該在Controller
上過濾它,然後將它傳遞給View
或者我可以在View
上過濾嗎?
我認爲最好的做法是在模型視圖包含列出了各個領域
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應該分開