开发者

Multiple views or single view using flag on ViewModel

I have a situation where a controller action should result in the information about a given object being displayed differently depending on the user's permission on the object.

Currently the controller action code returns one of two views accordingly: Info.ascx or Info_ViewOnly.ascx.

As the differences between these two views are very minor (and I have just had to update each with a format change) I am considering having one view (Info.ascx) and passing the user's permission to the view using the View's Model.

Which approach would you consider preferable? Alternative suggesti开发者_如何学运维ons also welcome :-)


The presence of "If Else" logic in your views is a good indication that you may need to split the view into multiple respective views. Your controller is probably the best place to assess user permissions and route the request to the most appropriate view - therefore that "If Else" logic should probably occur in the controller rather than the view.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜