0

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

2
  • Out of curiosity, are you simply trying to hide a logon or register button/link based on if a user is authenticated or not? Commented Mar 11, 2012 at 22:52
  • @rfmodulator: i am trying to hide a button if user is the current user. Commented Mar 11, 2012 at 23:12

2 Answers 2

2

You can do that logic directly in the View:

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

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

}
Sign up to request clarification or add additional context in comments.

Comments

0

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.
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.