ASP.NET MVC - Job of Controllers

大憨熊 提交于 2019-12-05 18:54:25

Do you have dedicated ViewModels and Poco-Models? If this is the case you can handle the data from the services inside the ViewModel. I am quite happy with this uproach.

public class PackageViewModel()
{
    public PackageDetail{get;set;}
    public int PackageID{get;set;}
    public List<Package>Packages{get;set;}
    public string SomeFilterCriteria{get;set;}

    publlic void FillPackageList(IPackageService packageService)
    {       
        Packages = packageService.GetPackages(SomeFilterCriteria);      
    }
}

In Controller:

public ViewResult ListPackages(PackageViewModel model)
{
    model.FillPackageList(PackageService);
    return View("ListPackages",model);

}

I dont understand what you mean by "view model builders".

The controller is supposed to orchestrate all actions you want to occur in your view. If you pull this logic out into action filters, it's still doing the logic per route request, it's just going to be cleaner in your case.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!