Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.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
Asp.net mvc 如何在asp.net mvc4上的webgrid中生成新行_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

Asp.net mvc 如何在asp.net mvc4上的webgrid中生成新行

Asp.net mvc 如何在asp.net mvc4上的webgrid中生成新行,asp.net-mvc,asp.net-mvc-4,Asp.net Mvc,Asp.net Mvc 4,我有一个文本框和一个按钮。单击按钮时,我需要在Web网格中添加文本框值。我编码为在网格中添加文本框值,但在同一列单元格中,该值将被更新。我需要生成新列并添加值 Index.cshtml代码 @{ @Html.TextBox("Value", "", new { id = "txtid" }) <input type="button" value="Submit" onclick="onSelectedIndexChanged()" id="btn" /> We

我有一个文本框和一个按钮。单击按钮时,我需要在Web网格中添加文本框值。我编码为在网格中添加文本框值,但在同一列单元格中,该值将被更新。我需要生成新列并添加值

Index.cshtml代码

@{
    @Html.TextBox("Value", "", new { id = "txtid" })
    <input type="button" value="Submit" onclick="onSelectedIndexChanged()" id="btn" />
    WebGrid grid = new WebGrid(Model, selectionFieldName: "SelectedRow");
    @grid.GetHtml(
        columns: grid.Columns(
            grid.Column("Edit", header: null, format: @<text>@item.GetSelectLink("Edit")</text>),
            grid.Column("Firstname", format: @<text>@item.GivenName</text>),
            grid.Column("Surname", format: @<text>@item.Surname</text>),
            grid.Column("Age", format: @<text>@item.Age</text>)
        )

    )
}
型号代码: 人民网

public  ObservableCollection<People> GetCustomerList(string firstname)
         {
             ObservableCollection<People> CustomerList = new ObservableCollection<People>();
             DataTable dtCustomer = new DataTable();

             CustomerList.Add(new People { Id = i, GivenName = firstname, Surname = "Kumar", Age = 25 });
                 i++;
             return CustomerList;
         }
控制器代码: 家庭控制器 公共操作结果GetPeoplestring firstname {

       //List<People> ItemList = new List<People>();
       // ViewBag.Items = ItemList;
        ObservableCollection<People> ItemList = new ObservableCollection<People>();
        People Customer = new Models.People();

        ItemList = Customer.GetCustomerList(firstname);

        return PartialView("Index", ItemList);

    }

webgrid只呈现一个html表。