简体   繁体   English

如何在 Razor 页面中发布表格单元格值

[英]How to post table cell value in a Razor page

Looking for ideas on how to pass the 'RecordId' value for the specific row in the table, when the 'view details' button for that row is pushed.当按下该行的“查看详细信息”按钮时,寻找有关如何传递表中特定行的“RecordId”值的想法。 This project is .NET Core 5 Web app with Razor pages.该项目是带有 Razor 页面的 .NET Core 5 Web 应用程序。 I'm not set on the button, open to other ideas to post the value and display the details.我没有设置按钮,对其他想法开放以发布值并显示详细信息。 Here is snippet of code generating the table rows:这是生成表行的代码片段:

                    @foreach(var x in  Model.masterrecords)
                    {
                        <tr class="border text-center">
                            <td>@x.RecordId</td>
                            <td>@x.FirstName</td>
                            <td>@x.LastName</td>
                            <td>@x.NumberOfRecords</td>
                            <td>
                                <input type="submit" asp-page-handler="ViewDetailsBtn" value="view details" class="btn btn-sm" />
                            </td>
                        </tr>
                    }

Try to use a form to post RecordId :尝试使用表单发布RecordId

@foreach (var x in Model.masterrecords)
        {
            <tr class="border text-center">
                <td>@x.RecordId</td>
                <td>@x.FirstName</td>
                <td>@x.LastName</td>
                <td>@x.NumberOfRecords</td>
                <td>
                    <form method="post"  asp-page-handler="ViewDetailsBtn" asp-route-RecordId=@x.RecordId>
                        <input type="submit" value="view details" class="btn btn-sm" />
                    </form>
                </td>
            </tr>
        }

handler(If your RecordId is string type,try to use string RecordId ):处理程序(如果您的 RecordId 是string类型,请尝试使用string RecordId ):

public void OnPostViewDetailsBtn(int RecordId)
        {
            
        }

result:结果: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM