开发者

Asp.Net MVC SelectList Refactoring Question?

开发者 https://www.devze.com 2022-12-18 11:00 出处:网络
I am currently re开发者_运维百科factoring 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

I am currently re开发者_运维百科factoring 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号