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

时间:2013-09-13 05:38:13

标签: asp.net-mvc asp.net-mvc-4

我有文本框和Button.I需要在单击按钮时在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;
         }

控制器代码: Home 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);

    }

0 个答案:

没有答案