这是code业务逻辑或presentation逻辑是什么? [英] Is this code business logic or presentation logic?

查看:162
本文介绍了这是code业务逻辑或presentation逻辑是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这code在视图中存在:

This code exists in a View:

       if (Model.Group.IsPremium && null != Model.Group.ContactInfo)
       {
           Html.RenderPartial("ContactInfo", Model.Group.ContactInfo);
       }

乍一看,这是presentation逻辑所以没关系。但它不是我坐好。

at first glance, it's presentation logic and so it's ok. But it's not sitting well with me.

问题是,如果组被分类为premium,这意味着他们支付它的业务要求,以显示联系人信息。

The thing is, it's a business requirement to display contact info if the group is classified as premium, which means they paid.

你们觉得呢?如果这种逻辑被转移到一个或者的HtmlHelper通过其他方法抽象出来?或者这是查看的预期使用情况如何?什么是做这个code的最好的事情?

What do you guys think? Should this logic be moved into a HtmlHelper or abstracted away by some other means? Or is this the intended usage of the View? What's the best thing to do with this code?

推荐答案

我产生封装此逻辑为布尔DisplayContactInfo属性视图模型。这取决于你如何干净想你的意见。

I'd produce a ViewModel that encapsulates this logic as a boolean DisplayContactInfo property. It depends on how "clean" you want your views.

这篇关于这是code业务逻辑或presentation逻辑是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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