且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从View移动逻辑控制器和视图模型

更新时间:2023-08-23 14:26:34

不要太担心 premature优化。我认为你是在正确的道路上这里就不会担心太多。

Don't worry too much about premature optimization. I think you're on the right path here and wouldn't worry too much about it.

您可以从构造方法中,如果你真的担心骨感控制器填充视图模型。

You could populate the ViewModel from within the Constructor if you're really worried about "skinny" controllers.

public class ManagerViewModel 
{

    public ManagerViewModel(ManagerModel model){
        // initialize in here
        this.Manager = model.Store.EmployeeType.Name == "Manager" ? model.Store.HQ.Manager.DisplayName : model.Store.Manager.DisplayName;
    }

    public string Manager {get;set;}
}

var viewModel = new ManagerViewModel(model);
return View(viewModel);