Johnson Duru
Johnson Duru

Reputation: 682

How to hide a button or link in asp.net Mvc View

i have this in my controller action in MVC

        if (Profileid == User.Identity.Name)
        {
           ViewBag.Data = true;
        }

i want to hide a button or link in my view when this condition is met.how do i go about this in my View. I am using Razor view. thanks

Upvotes: 0

Views: 5181

Answers (2)

Pasha Immortals
Pasha Immortals

Reputation: 839

Try: If you want based on ViewBag try this:

@if(ViewBag.Data == true)
{
//Put code here.
}

Or based on ProfileId:

@if(ProfileId == User.Identity.Name)
{
//Put code here.
}

Upvotes: 0

Alex
Alex

Reputation: 35399

You can do that logic directly in the View:

@if (Profileid == User.Identity.Name) {

    <input type="submit" ... />

}

Upvotes: 2

Related Questions