0
我有一個MVC WebApp,我正在成功驗證Azure AD角色並將其拖放到我的應用中。如何根據角色在我的_Layout.cshtml文件中顯示或隱藏像'home''等'左右導航欄選項卡?MVC Webapp隱藏/顯示帶有Azure AD角色的網站選項卡
我可以授權頁面在控制器[Authorize(Roles = "")]
但我想隱藏在導航欄級別。我錯過了什麼代碼行來使這個動態?
這裏是我的_Layout.cshtml文件中的代碼,我希望做到這一點:
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("My Project", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
@Html.Partial("_LoginPartial")
</div>
提前幫助謝謝!
完美地工作!謝謝你的快速反應。 – Alex
很高興提供幫助。請務必檢查正確的答案,以便其他遇到同樣問題的人可以更輕鬆地找到答案。 –