【问题标题】:Invoke ViewComponent after action method在操作方法之后调用 ViewComponent
【发布时间】:2016-01-13 05:04:45
【问题描述】:

我有以下布局页面:

<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动作方法被调用后,怎么做?

【问题讨论】:

    标签: c# asp.net-core asp.net-core-identity asp.net-core-viewcomponent


    【解决方案1】:

    我找到了解决方案。我需要做的就是RedirectToAction(),而不是返回一个视图。

    【讨论】:

      猜你喜欢
      • 2014-12-21
      • 1970-01-01
      • 1970-01-01
      • 2018-02-02
      • 2010-11-05
      • 2023-04-08
      • 2014-02-10
      • 1970-01-01
      • 2013-07-28
      相关资源
      最近更新 更多