具有多个参数的.NETCore详细信息列表

时间:2017-10-03 04:09:36

标签: c# asp.net-mvc entity-framework

我有一个项目列表,我希望用户通过点击以下链接查看其他页面中的详细信息:

<td><a data-toggle="modal" data-target="#modal-action-user" asp-area="" asp-controller="DuctWorks" asp-action="ForceItem" class="itemClick text-muted">@dw.Item</a></td>

此链接调用如下的ajax来读取表的列并将它们传递给控制器​​:

<script type="text/javascript">
    $(document).ready(function () {
        // Pass item information to controller
        $(".itemClick").on('click', function () {
            var currentRow = $(this).closest("tr");
            var col1 = currentRow.find("td:eq(0)").html();
            var col2 = currentRow.find("td:eq(1)").html();
            var col3 = currentRow.find("td:eq(2)").html();
            var col4 = currentRow.find("td:eq(3)").html().substring(114);
            col4 = col4.replace('</a>', '');
            $.ajax({
                type: "Post",
                //async:true,
                url: "/DuctWorks/ForceItem",
                data: {
                        jInv: col1,
                        jName: col2,
                        jDwg: col3,
                        iName: col4
                },
                success: function (data) {
                }
            });
        });
    });
</script>
然后

Controller接收参数并将它们传递给相关视图:

public IActionResult ForceItem(string jInv, string jName, string jDwg, string iName)
    {
        Change_sts changests = new Change_sts()
        {
            job_inv = jInv,
            job_name = jName,
            job_dwg = jDwg,
            item_name = iName
        };
        ViewBag.jInv = changests.job_inv;
        ViewBag.jName = changests.job_name;
        ViewBag.jDwg = changests.job_dwg;
        ViewBag.item = changests.item_name;
        return View();
    }

我试过这个链接(https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/crud),但它只使用一个参数作为id。

我的代码不起作用显然它被调用两次并导致数据丢失。是否有参考或解决方案,我可以更多地了解这个问题?

0 个答案:

没有答案