Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我想使用jquery将行插入WebGrid_C#_Jquery_Asp.net Mvc_Model View Controller_Webgrid - Fatal编程技术网

C# 我想使用jquery将行插入WebGrid

C# 我想使用jquery将行插入WebGrid,c#,jquery,asp.net-mvc,model-view-controller,webgrid,C#,Jquery,Asp.net Mvc,Model View Controller,Webgrid,我想使用Jquery将行插入webgrid。 我将从页面上的文本框中获取我的值 var grid1 = new WebGrid(Model.dsvm as IEnumerable<ASP_Upload_Version_1.Models.Share_Template>, canPage: true, canSort: false); @grid1.GetHtml(tableStyle: "table table-sm table-

我想使用Jquery将行插入webgrid。 我将从页面上的文本框中获取我的值

var grid1 = new WebGrid(Model.dsvm as IEnumerable<ASP_Upload_Version_1.Models.Share_Template>, canPage: true, canSort: false);
                            @grid1.GetHtml(tableStyle: "table table-sm table-striped table-bordered table-condensed",
                            htmlAttributes: new { @id = "GridPractice", @class = "table table-sm table-striped table-bordered table-condensed", @style = "width:100%" },
                            columns: grid1.Columns(
                            grid1.Column("PracticeArea", "Practice Area"),
                            grid1.Column("MarketArea", "Market Area"),
                            grid1.Column(format: @<text>
                                    <a data-title="Are you sure to deactivate this Input?"><i class="fa fa-trash" style="color:red"></i></a></text>, header: "Remove")));

以下jquery函数正常工作:

$("#Submit_AddRow1").click(function () {
    //Reference the WebGrid.
    var webGrid = $("#GridPractice");

    //Reference the first row.
    var row = webGrid.find("tr").eq(1);

    //Check if row is dummy, if yes then remove.
    if ($.trim(row.find("td").eq(0).html()) == "") {
    row.remove();
    }

    //Clone the reference first row.
    row = row.clone(true);

    //Reference the Practice Area TextBox.
    var txtfoo = $("#txtfoo");

    //Reference the Market Area TextBox.
    var txtbar = $("#txtbar");

    //Add the Practice Area value to first cell.
    SetValue(row, 0, txtfoo);

    //Add the Market Area value to second cell.
    SetValue(row, 1, txtbar);

    //Add the row to the WebGrid.
    webGrid.append(row);
});

function SetValue(row, index, textbox) {
    //Reference the Cell and set the value.
    row.find("td").eq(index).html(textbox.val());

    //Clear the TextBox.
    textbox.val("");
}
$("#Submit_AddRow1").click(function () {
    //Reference the WebGrid.
    var webGrid = $("#GridPractice");

    //Reference the first row.
    var row = webGrid.find("tr").eq(1);

    //Check if row is dummy, if yes then remove.
    if ($.trim(row.find("td").eq(0).html()) == "") {
    row.remove();
    }

    //Clone the reference first row.
    row = row.clone(true);

    //Reference the Practice Area TextBox.
    var txtfoo = $("#txtfoo");

    //Reference the Market Area TextBox.
    var txtbar = $("#txtbar");

    //Add the Practice Area value to first cell.
    SetValue(row, 0, txtfoo);

    //Add the Market Area value to second cell.
    SetValue(row, 1, txtbar);

    //Add the row to the WebGrid.
    webGrid.append(row);
});

function SetValue(row, index, textbox) {
    //Reference the Cell and set the value.
    row.find("td").eq(index).html(textbox.val());

    //Clear the TextBox.
    textbox.val("");
}