我有以下布局页面:
<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");
}
}
我想在调用LogOut操作方法之后渲染ViewComponent ,该怎么做?
答案 0 :(得分:0)
我找到了解决方案。我需要做的就是RedirectToAction()
,而不是返回视图。