0

我有以下頁面佈局後:調用ViewComponent操作方法

<body> 
<nav>@Component.Invoke("Navigation")</nav> 
<main>@RenderBody()</main> 
</body> 

ViewComponent這使得用於身份驗證,未通過身份驗證的用戶兩種不同的觀點:

public class NavigationViewComponent : ViewComponent 
{ 
    public IViewComponentResult Invoke() 
    { 
     if(User.Identity.IsAuthenticated) 
     { 
      return View("User"); 
     } 
     return View("Guest"); 
    } 
} 

我也有一個動作方法註銷用戶:

public class HomeController : Controller 
    ... 
    public async Task<IActionResult> LogOut() 
    { 
     await _signInManager.SignOutAsync(); 
     return View("Index"); 
    } 
} 

我想呈現ViewComponent LogOut操作方法被調用,該怎麼做?


回答

0

我找到了解決方案。我需要做的就是RedirectToAction(),而不是返回一個View。

相關問題