This is a migrated thread and some comments may be shown as answers.

Button upload Image in grid

1 Answer 350 Views
Grid
This is a migrated thread and some comments may be shown as answers.
david
Top achievements
Rank 1
david asked on 19 May 2014, 09:47 AM
Hello. 

I'm trying to add a button to upload an image in the grid. The problem is when the row is "saved". All elements of the file are stored, but the byte [] (picture) never reaches the controller.

He conseguido rellenar el grid mediante javascript





But when i try to save, the object received controller is empty in field img



@(Html.Kendo().Grid<InventarioMerlin.Models.ContadorModelo>()
    .Name("GridContadorModelo")
    .Columns(columns =>
    {
        columns.Bound(p => p.id).Visible(false).Width(100);
        columns.Bound(p => p.nombre).Width(100);
        columns.Bound(p => p.isenabled).Width(100);
        columns.Bound(p => p.img).Width(100);
        columns.Command(c => c.Custom("Upload").Click("upload")).Title("Grafica").Width(100);
        columns.Bound(p => p.grafica).Width(100);
        
        columns.Command(command => { command.Edit(); }).Width(200);
    })
                    .ToolBar(toolbar => { toolbar.Create(); toolbar.Save(); })
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Pageable(p => p.Refresh(true))
    .Sortable()
    .Scrollable()
    .HtmlAttributes(new { style = "height:100%;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)    
        .Events(events => events
            .Error("error_handler")
            .RequestEnd("onRequestEnd"))
            .Model(model =>
                        {
                            model.Field(p => p.img).Editable(true);
                            model.Id(p => p.id);
                            model.Field(p => p.id).Editable(false);
                            model.Field(p => p.isenabled).DefaultValue(true);
                        })
            .Create(create => create.Action("ContadorModelo_Popup_Create", "Contador"))
            .Read(read => read.Action("ContadorModelo_Popup_Read", "Contador"))
            .Update(update => update.Action("ContadorModelo_Popup_Update", "Contador"))
            //.Destroy(update => update.Action("EditingPopup_Destroy", "Ccoconfiguraciones"))
    )
        )
 
 
 
function upload(e)
    {
         
        e.preventDefault();
        rowSelected = this.dataItem($(e.currentTarget).closest("tr"));
       
        $('#myModal').modal({
            show: true
        })
 
        
    }
 
 $("#btnSaveChanges").click(function () {
        refreshGrid();
        $('#myModal').modal('hide');
    });
 
 
function refreshGrid()
    {
        var grid = $("#GridContadorModelo").data("kendoGrid");
        var dataSource = grid.dataSource;
        var data = dataSource.data();
        $.each(data, function (index, rowItem) {
            if (rowItem.id == rowSelected.id) {
                rowItem.img = imageUploaded;
                rowSelected.dirty = true;
            }
        });
        grid.refresh();
         
    }


1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 21 May 2014, 07:27 AM
Hello,

What is the value of the imageUploaded parameter? The MVC default model binder expects a base64 string to be posted for a byte array.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
david
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or