簡體   English   中英

重定向到查看組件頁面 ASP.NET CORE

[英]Redirecting to View Component page ASP.NET CORE

我最近將我的WorkShift視圖頁面更改為視圖組件。 但是,我現在不能用我的按鈕 go 進入視圖組件。 對我的視圖組件來說,我的asp-action應該是什么?

我的新視圖組件位於 Views->Home->Components->WorkShift->Default.cshtml

我的視圖頁面中的按鈕在 go 進入視圖組件頁面時應該如何?

看法:

<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>

您可以要求 controller 操作返回 ViewComponent。這是一個演示:

家庭控制器:

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

視圖/主頁/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>

結果: 在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM