ASP.NET MVC - Form Value display by role [duplicate]
Possible Duplicate:
ASP.NET MVC - Form Value display by role
I'm looking for an ideal way for my input forms to either show as a textbox (editable), label (readonly), or hidden (no access) based on the roles. I know I could have a different view for each type of role but I was hoping that there's some new goodness out there that would p开发者_如何学Pythonrevent me from having to do 80 views.
Add a DisplayMode property to your model and customise the View accordingly. That way if you decide to change the rules over what role sees what version of the View you only have to update the Controller, not the View.
I'd write a simple WebControl that you can pass the data to and the, as @ctford suggests, display mode.
Depending on the display mode passed to the WebControl you could then either render a TextBox, Label or Hidden field.
Nice, neat and reusable.
精彩评论