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。

相关问题