简体   繁体   English

如何在asp.net Mvc View中隐藏按钮或链接

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

i have this in my controller action in MVC 我在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. 我正在使用Razor视图。 thanks 谢谢

You can do that logic directly in the View : 您可以直接在View执行该逻辑:

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

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

}

Try: If you want based on ViewBag try this: 尝试:如果你想基于ViewBag试试这个:

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

Or based on ProfileId: 或者基于ProfileId:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM