MVC 3 Edit data in a IEnumerable Model View

后端 未结 1 731
不知归路
不知归路 2021-01-05 00:35

I\'m trying to edit a list of items in a strongly-typed razor view. The templates don\'t give me the option to edit a list of objects in a single view so I merged the List v

1条回答
  •  礼貌的吻别
    2021-01-05 01:10

    How do i do it? FormCollection? Viewdata?

    None of the above, use the view model:

    [HttpPost]
    public ActionResult EditPermissoes(IEnumerable model)
    {
        // loop through the model and for each item .HasPermissao will contain what you need
    }
    

    And inside your view instead of writing some loops use editor templates:

    
        @Html.EditorForModel()
    
    Indicador Nome Descrição

    and inside the corresponding editor template (~/Views/Shared/EditorTemplates/Permissao.cshtml):

    @model Permissao
    
        
            @Html.CheckBoxFor(x => x.HasPermissao)
        
        
            @Html.DisplayFor(x => x.TipoP.IndID)
        
        
            @Html.DisplayFor(x => x.TipoP.Nome)
        
        
            @Html.DisplayFor(x => x.TipoP.Descricao)
        
    
    

    0 讨论(0)
提交回复
热议问题