重定向到查看组件页面 ASP.NET CORE

Redirecting to View Component page ASP.NET CORE

我最近将 WorkShift 视图页面更改为视图组件。但是,我现在无法使用我的按钮进入视图组件。我的 asp-action 中应该包含哪些内容才能转到我的视图组件?

我的新视图组件在Views->Home->Components->WorkShift->Default.cshtml

要进入视图组件页面,我的视图页面中的按钮应该是什么样子?

查看:

<div class="form-row">
    <div class="form-group col-md-4">
        <a asp-action="WorkShift" class="btn btn-secondary btn-block"><i class=" fa fa-table"></i>Back to List</a>
    </div>
</div>

您可以要求控制器操作 return ViewComponent.Here 演示是否有效:

家庭控制器:

public IActionResult TestButton()
    {
        return View();
    }
    public IActionResult ReturnViewComponent() {
        List<notes> list = new List<notes> { new notes { Id = "1", Notes = "note1", LastModifedDate = "2020/01/01", LastModifiedBy = "Joy" }, new notes { Id = "2", Notes = "note2", LastModifedDate = "2020/01/02", LastModifiedBy = "Tommy" }, new notes { Id = "3", Notes = "note3", LastModifedDate = "2020/01/03", LastModifiedBy = "Jay" } };
        return ViewComponent("Notes", list);
    }

ViewComponents/Notes.cs:

public class Notes:ViewComponent
    {
        public async Task<IViewComponentResult> InvokeAsync(List<notes> list)
        {
            return View(list);
        }
    }

ViewComponent 位置: Views/Home/Components/Notes/default.cshtml

Views/Home/TestButton.cshtml:

<h1>TestButton</h1>
<div>
    <a asp-action="ReturnViewComponent" class="btn btn-secondary btn-block"><i class=" fa fa-table"></i>Back to List</a>
</div>

结果: