2

我正在尝试一次从简单的网格中添加多个对象。关注文章http://www.donnfelker.com/editable-grid-list-binding-in-mvc2/ 但可能遗漏了一些我无法弄清楚的东西。在我的控制器中,随着项目发布,我得到空值

看法:

    @model List<ItemClass>
    @using (Html.BeginForm("Action", "Controller", FormMethod.Post))
    {
        <table>
        <thead>
            <th>PropertyA</th>
            <th>PropertyB</th>
        </thead>
    @for (int i = 0; i < Model.Count; i++)
    {
        @(Html.EditorFor(m => Model[i], "TemplateName"))
    }
        </table>
        <button type="submit" value="Submit"></button>
    }

单个项目的编辑模板:

    @model ItemClass
    <tr>
        <td>
           @Html.EditorFor(m => Model.PropertyA)
        </td>
        <td>
           @Html.EditorFor(m => Model.PropertyB)
        </td>
    </tr>

控制器:

    [HttpPost]
    public ActionResult CreateItems(List<ItemClass> items)
    {
        //create in db
        return RedirectToAction("XXXXXX");
    }
4

1 回答 1

1
Try this

[HttpPost]
    public ActionResult CreateItems(List<ItemClass> items)
    {


//       Impelement the for loop with the parameter items varialbe to store the values 
  //     in database 

       for(int i= 0 ; i<item.count; i ++)

        {
           //Implement insertion logice here.

        }

        return RedirectToAction("XXXXXX");
    }
于 2013-08-22T12:00:56.673 回答