I have an Extension Method that verifies if the user is able to see a portion of the webpage, based on a Role.
If I simple remove the content, this brings me more work as all the missing forms will not be correctly registered upon save and I have to deal with this behavior by modifying all my code, so I thought why not just use display:none;
attribute?
I would like to have something like:
@using(Html.RoleAccess(currentUser, RoleAccessType.Content_General_Website))
{
...
}
and that this would write something like:
<div class="role_Content_General_Website" style="display:none;">
...
</div>
or use display:block;
if the user has access...
I can create a simple HtmlHelper
but how do I write one that also outputs the ending </div>
?
public static string RoleAccess(
this HtmlHelper helper,
UserInfo user,
RoleAccessType role)
{
return
String.Format(
"<div class='role_{0}' style='display:{1}'>",
role.ToString(), user.HasAccess(role));
}
and then you can use it like this:
You could obviously adapt the arguments of the helper to match your requirements: