首页 > 解决方案 > 如何在 asp.net-mvc 中添加 actionlink?

问题描述

我试图将 actionlink 添加到我的代码中,但是。我无法产生正确的看法。

table class="table table-bordered table-striped table">
    <thead>
        <tr>
            @foreach (System.Data.DataColumn col in Model.Columns)
            {
                <th>@col.Caption</th>
            }
        </tr>
    </thead>
    <tbody>
        @foreach (System.Data.DataRow row in Model.Rows)
        {
            <tr>
                @foreach (var cell in row.ItemArray)
                {
                    <td>@cell.ToString()</td>
                }
            </tr>
            <tr>
                @foreach (var cell in row.ItemArray)
                {

                    <td>@Html.ActionLink("Click for rent this car", "IntoSaleTable")</td>
                }
            </tr>
        }
        }
    </tbody>

由于上述代码 1

我的代码为单行生成多个操作链接,但我每行只需要一个操作链接。

标签: c#asp.netasp.net-mvc

解决方案


根据您的评论,试试这个:

<table class="table table-bordered table-striped table">
    <thead>
        <tr>
            @foreach (System.Data.DataColumn col in Model.Columns)
            {
                <th>@col.Caption</th>
            }
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (System.Data.DataRow row in Model.Rows)
        {
            <tr>
                @foreach (var cell in row.ItemArray)
                {
                    <td>@cell.ToString()</td>
                }
                <td>@Html.ActionLink("Click for rent this car", "IntoSaleTable")</td>  <!-- use row["Id"] to pass Id or somethig-->
            </tr>
        }
    </tbody>
</table>

推荐阅读