开发者

Multiple views or single view using flag on ViewModel

开发者 https://www.devze.com 2023-01-22 01:32 出处:网络
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.

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

精彩评论

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