MVC - Is it possible to place an EditorFor inside a column in Webgrid?

2

I have a EditorTamplate and I need to put a EditorFor , using this EditorTemplate , as a column inside Webgrid .

How could I do this?

I tested the form below and gave the error shown in the image.

    
asked by anonymous 16.09.2015 / 22:35

2 answers

1

I have a table with columns that change the type of component (text, button, link) according to the logged-in user. So I decided to use Editortemplate. After many attempts, I gave up editorFor and am using Editor . Now it worked fine the way I put it down.

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
    )       


};
    
19.09.2015 / 01:07
3

Yes you can, you can try:

grid.Column("Text", "Text", canSort: true, format: @<text>@Html.EditorFor(item => item.Propriedade)</text>)
    
16.09.2015 / 23:23