MVC - 可以在WebGrid的列中放置一个EditorFor吗?

时间:2015-09-16 19:49:23

标签: asp.net-mvc-4 webgrid mvc-editor-templates editorfor

我有一个EditorTamplate,需要使用此EditorTemplate将EditorFor作为WebGrid中的一列。我怎么能这样做?

我尝试了它的打印方式,但下面给出错误。

enter image description here

1 个答案:

答案 0 :(得分:0)

我有一个包含列的表,根据记录的用户更改组件类型(文本,按钮,链接)。所以我决定使用Editortemplate。经过多次尝试,我放弃了editorFor,我正在使用Editor。现在它按照你下面的方式工作得很好。

var columns = new WebGridColumn[] {
    grid.Column("CodigoDesenho", ODMResources.PartNumber, style: "center"),          //1
    grid.Column("Descricao", ODMResources.APNPartDescription, style: "center"),      //2
    grid.Column(                                                    //3
            "ModoFornecimento", 
            ODMResources.APNModoFornecimento, 
            (item) => @Html.Editor("ModoFornecimento", "ModoFornecimento", new { ModoFornecimentoCod = item.ModoFornecimento, Codigo = Options.COD_OPCAO_VALOR_TIPO_FORNECIMENTO, idOdm = item.IdODM, codigoDesenho = item.CodigoDesenho, disabled = !item.GestorCodep.Equals(this.User.Identity.Name) }) ,
            "center", 
            false
        ),
    grid.Column("VariacaoIntroduzida", ODMResources.APNVariacaoIntroduzida, style: "center"),      //4
    grid.Column(                                                    //5
        "Codesign", 
        ODMResources.APNCodesign, 
        (item) => @Html.Editor("Codesign", "Codesign", new { Codesign = item.Codesign, isUsuarioLider = @isLider, idOdm = item.IdODM, codigoDesenho = item.CodigoDesenho }) ,
        "center", 
        false
    )       


};