I have a few partial views that should render when the user has a certain Role.
Now, I want to avoid doing something like
<% if(user is in role){..here goes the html.. }%>
I would like to be able to do (at the top of the ascx) :
<% this.RenderOnlyForRoles(list of roles) %>
Now, in the BasePartialView I have a list of roles that gets populated when RenderOnlyForRoles is called.
The problem is that the RenderOnlyForRoles is called after .. all events I can think of :) and I can't stop the rendering of the control.
Any ideas on how to obtain what I want ?
EDIT: Anyone knows if other viewengines might support this ?
Use an HTMLHelper
public static void RenderOnlyForRoles(this HtmlHelper html, List<string> roles))
{
if (check if user in roles)
{
html.RenderPartial(yourview);
}
}
Kindness,
Dan
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With