我可以在 Razor 页面中传递值局部视图吗?

can i pass value partial view in razor page?

我可以在 Razor 页面中传递值局部视图吗?

我会依次解释代码。 这是第一个

点击跨度文本发送 (1924)

<span onclick="CallViewBorad(1924)">1924 </span>

<script>
    function CallViewBorad(boardId)
    {
        alert(boardId);
         $('#RightSector').load('/TreeView?handler=BoardPartial&boardid=' + boardId);
    }
</script>

int板为2

$('#RightSector').load('/TreeView?handler=BoardPartial&boardid=' + boardId);

这是工作

如何用这个发送数据

public PartialViewResult OnGetBoardPartial(int boradid)
{
    contentOn = true;

    IQueryable<tbl_comment> Comment = from m in _context.tbl_comment
                                      where m.board_id == boradid
                                      orderby m.comment_date
                                      select m;
    ilist = Comment.ToList();

    return Partial("ViewBoardPartial", ilist);
}

我可以访问这部分但是模型是空的

@page "{handler?}"
@using WebApplication1.Models
@model IList<tbl_comment>

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<head>
    <script src="~/jsDemo/chart-area-demo.js"></script>
</head>

@if (Model != null)
{
    foreach (var item in Model)
    {
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">작성자: @item.user_id 날짜: @item.comment_date</h6>
        </div>
        <div class="card-body" style="color :black">
            @Html.Raw(item.comment_content)
            <hr>
            <script src="~/jsDemo/chart-area-demo.js"></script>
        </div>
    </div>
    }
}

局部视图是剃刀视图而不是剃刀page.So您需要创建一个剃刀视图作为局部视图,并在局部视图中删除@page "{handler?}",并且您需要确保部分视图位于 Shared 文件夹或剃须刀页面的同一文件夹中: 部分查看代码:

@using WebApplication1.Models
@model IList<tbl_comment>


@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<head>
            <script src="~/jsDemo/chart-area-demo.js"></script>
</head>

@if (Model != null)
{
    foreach (var item in Model)
    {
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">작성자: @item.user_id 날짜: @item.comment_date</h6>

        </div>

        <div class="card-body" style="color :black">
            @Html.Raw(item.comment_content)

            <hr>

            <script src="~/jsDemo/chart-area-demo.js"></script>

        </div>

    </div>
    }
}

结果: