Asp.Net MVC的SelectList重构问题? [英] Asp.Net MVC SelectList Refactoring Question?

查看:173
本文介绍了Asp.Net MVC的SelectList重构问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在重构我们的凌乱的控制器。我们在我们的控制器有很多SelectLists的。我想办法使它更易于维护我们的code基地。这将是一个很好的解决方案工厂方法,接口或基类?我们有很多这些方法漂浮在我们的code。

 私人的SelectList getRateContract(IEnumerable的项目)
    {
        返回新的SelectList(物品,Resources.RSINET.RateContractID,Resources.RSINET.ContractName);
    }


解决方案

首先,如果他们躺在控制器,这些方法至少应该与无为属性。

选择列表的建立将,在我看来,在视图模型做的,但不是每个人都使用的模型以同样的方式(我知道微软不)。你应该有你的模型的调用创建此选择列表。这样,控制器停留在...好,应用程序流控制,模型不包含数据的工作。

I am currently refactoring our messy controllers. We have a lot of SelectLists in our controllers. I want a way make it easier to maintain our code base. What would be a good solution a Factory Method, Interface or Base Class? We a lot of these methods floating around our code.

private SelectList getRateContract(IEnumerable items)
    {
        return new SelectList(items, Resources.RSINET.RateContractID, Resources.RSINET.ContractName);
    }

解决方案

For a start, if they lie in the controller, these methods should at least be decorated with the NonAction attribute.

The SelectList creation would, in my opinion, be done in the view model, but not everyone uses models in the same way (I know Microsoft don't). You should probably have a call to your model that creates this selectlist. That way, the controller stays in... well, control of the application flow, and the model does its job of containing the data.

这篇关于Asp.Net MVC的SelectList重构问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆