can i pass value partial view in razor page?

can i pass value partial view in razor page?

I will explain the code in sequence. This is the first

click span text send (1924)

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

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

int board is 2

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

it is work

how send data with this

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);
}

i can access this part but model is null

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

this

Answer

Partial view is a razor view rather than a razor page.So you need to create a razor view as a partial view,and remove @page "{handler?}" in partial view,and you need to make sure the Partial view is in Shared folder or in the same folder of the razor page: Partial view code:

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

result: enter image description here