I am using a View for adding a new user in Asp.net MVC4(Razor view engine). When a user which is in Admin role adds a new user, then i want to show a check-box to user which will say IsAdmin( for adding new user to Admin role) and when a new anonymous user register himself,then this check-box should not appear. For both case i want to use same View I am using Asp.netMVC4 Simple-membership.
So, Please tell me how i can achieve the same
I don't know how your site is set up, so it's hard to answer, but...
I will assume you're passing a model to your view from your controller.
If so, add a property to your model (in fact, this is a great time to use a ViewModel) of type bool. Make sure the value of your bool reflects the user role's rights as admin (true or false).
So, something like
public bool IsAdmin
{
get { return _isAdmin;}
set
{
_isAdmin = IsPartOfAdminRoleQuery();
}
}
Then, in your view, just call your Model like (you may need to use a Lamba or similar depending on how your model is set up)
@if (Model.IsAdmin)
//logic