How can I create a view that has different displays according to the role the user is in?

后端 未结 8 1391
南方客
南方客 2020-12-04 11:22

I want to create a view that has different displays according to the role the user is in.

Should I create a different view for different roles or should I check the

8条回答
  •  情书的邮戳
    2020-12-04 12:26

    If you are using MVC the whole point of development is to keep the logic out of the view and in the controller. It seems to me like you'd be better off on a WebForms development track than an MVC track.

    All that being said, I do an Admin check on a lot of my pages by using a check like this:

    <% if ((bool)ViewData["Admin"]) { %>
        
    <% } %>
    

    But if you are attempting to build actual logic into the View then you need to figure out what you can push back to the controller to do the work and have the view be as dumb as possible, acting on flags sent to it.

提交回复
热议问题