Home > Software design >  How to post table cell value in a Razor page
How to post table cell value in a Razor page

Time:10-20

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. This project is .NET Core 5 Web app with Razor pages. 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 >
                            <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"  />
                            </td>
                        </tr>
                    }

CodePudding user response:

Try to use a form to post RecordId:

@foreach (var x in Model.masterrecords)
        {
            <tr >
                <td>@x.RecordId</td>
                <td>@x.FirstName</td>
                <td>@x.LastName</td>
                <td>@x.NumberOfRecords</td>
                <td>
                    <form method="post"  asp-page-handler="ViewDetailsBtn" [email protected]>
                        <input type="submit" value="view details"  />
                    </form>
                </td>
            </tr>
        }

handler(If your RecordId is string type,try to use string RecordId):

public void OnPostViewDetailsBtn(int RecordId)
        {
            
        }

result: enter image description here

  • Related