ASP.NET MVC 4 How do you serve different HTML based on Role?

后端 未结 3 568
滥情空心
滥情空心 2021-01-19 04:44

On top of allowing only certain Roles to access certain Controller or Action, I would like to serve a slightly different HTML based on the roles.

Admin can see Edit

3条回答
  •  清歌不尽
    2021-01-19 05:41

    The solution you point to strikes me a very good one. A simpler (but perhaps harder to maintain) approach would be to pass a list of the user's roles has to the view (as a property of the model). In the view you would then have an if statement around the HTML displaying the button checking if the button should be displayed to the user.

提交回复
热议问题