如果页面以usig DataTable作为模型,如何将路线值添加到actionLink?

时间:2019-05-12 15:43:43

标签: c# asp.net-mvc datatable dataset

我正在研究简单的数据库项目。我需要使用actionLink来映射不同的动作。我在传递路由值时遇到麻烦。

索引操作方法:

[HttpGet]
        public ActionResult Index() {

            DataSet dt = new DataSet();

            using (SqlConnection sqlcon = new SqlConnection(connectionString)) {
                sqlcon.Open();
                SqlDataAdapter sqlDa = new SqlDataAdapter("SELECT CarInformation.ID,CarInformation.BRAND,CarInformation.OWNER_ID,CarInformation.PRICE,CarInformation.AVALIABLE_DAYS FROM CarInformation WHERE CarInformation.BRAND=(SELECT TOP 1 BRAND FROM Request ORDER BY REQUEST_ID DESC) AND (SELECT TOP 1 WISH FROM Request ORDER BY REQUEST_ID DESC)<=CarInformation.AVALIABLE_DAYS AND CarInformation.PRICE<=(SELECT TOP 1 PRICE FROM Request ORDER BY REQUEST_ID DESC)", sqlcon);
                sqlDa.Fill(dt, "CarInformation");
            }

            return View(dt.Tables["CarInformation"]);
        }

对应于动作链接的索引动作视图:

@model System.Data.DataTable

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>

                }
                <td>@Html.ActionLink("Click to rent", "IntoSaleTable",new {id= ,price=,})</td>
            </tr>

        }
    </tbody>
</table>

映射的动作:

public ActionResult IntoSaleTable(int id, int price) {
.
.
.

}

索引方法使我可以在屏幕上打印查询结果。 我需要做的是获取此输出的“ id”和“ price”列[1]

[1] https://imgur.com/Y0JERLa

0 个答案:

没有答案