繁体   English   中英

要从webgrid获取行中的值并将其传递给控制器

[英]To get the value in row from webgrid and pass it to the controller

我在Column中获得价值,以下是代码。

grid.Column(columnName: "Name", header: "Name",format: @<text>  
      <span id="Name">@item.Name</span></text>, canSort: false),

想要在删除按钮上调用的函数中使用此值

function DeleteEnterpriseID() {
        var checkID = $(".edit-mode:checked").map(function () {
            return this.value;
        }).toArray();
        alert(checkID.join(","));

        if (confirm("Are you sure you want to delete?") == true) {
            var url = "@Url.Action("DeleteEnterpriseIdDetails")";
            var pname = $('#Name').val();  //// Here I want that value from the clicked row so that I can pass that to controller.
            alert(pname);
            $.ajaxSetup({ cache: false });
            $.post(url, { Pname: pname, EnterpriseID: checkID.join(",") })
            .success(function (response) {
                if (response != null && response.success) {
                    alert(response.responseText);
                    window.location.href = response.newurl;

                } else {
                    alert(response.responseText);
                }
            })
            .error(function (response) { alert("error"); });
        }
        else {
            return false;
        }
    }

但是我从单击的行中获取名称的空白值。 请协助。

它应该是:

var pname = $('#Name').text();

因为它是一个span标签,而不是输入元素。 val()适用于输入元素。

暂无
暂无

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

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