1

我有文本框和一个按钮。单击按钮时,我需要在 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>)
        )

    )
}

型号代码:People.cs

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;
         }

控制器代码:首页 Controller.cs public ActionResult GetPeople(string 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);

    }
4

0 回答 0