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

Grid popup template with upload component not returning any values

3 Answers 300 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Jonatan
Top achievements
Rank 1
Jonatan asked on 03 Dec 2015, 09:19 AM

I have a Grid with a popup that has an upload module. after uploading a file to the server, I want the "Success" event to populate a hidden field for the model.

The code is as follows.

GRID________________________________________________

@(Html.Kendo().Grid<BlueWebApp.Models.Note>()
    .Name("NoteGrid")
    .Columns(columns =>
    {
        columns.Bound(c => c.NoteID).Width(50);
        columns.Bound(c => c.NoteText).Width(150).Title("Text");
        columns.Command(c => c.Edit());
    })
    .HtmlAttributes(new { style = "height: 600px; width: 100%" })
    .Editable(ed => { ed.Mode(GridEditMode.PopUp).TemplateName("NoteEditTemplate"); })
.ToolBar(e => e.Create())
.Pageable(pageable => pageable
    .Refresh(true)
    .PageSizes(true)
    .ButtonCount(5))
.DataSource(dataSource => dataSource
    .Ajax()
    .Read(read => read.Action("GetNotes", "Note"))
    .Create(c => c.Action("CreateNote", "Note"))
    .Update(u => u.Action("UpdateNote", "Note"))
    .Model(m =>
    {
        m.Id(p => p.NoteID);
    })
    )
)
 

 

EDITORTEMPLATE_______________________________

@model BlueWebApp.Models.Note
 
<div style="height: 100px;">
    This is customized Person edit template
 
        @Html.HiddenFor(model => model.NoteID)
        <br />
        @Html.HiddenFor(model => model.NoteText, new { id = "test"})
                 
</div>
<div>
    @(Html.Kendo().Upload()
         .Name("files")
         .Events(events => events.Success(
         @<text>
    function(e) {
        $('#test').val(e.response.fileName);
    
    }
        </text>))
         .Multiple(false)
         .Async(a => a.Save("Save", "Note")
                      .Remove("Remove", "Note")
                      .AutoUpload(true)
        )
 
)
</div>
<br />

When clicking the "Update" button on the popup the hidden field with id Test has been given a value. but that value is not passed to the model.

 What am I doing wrong?

 
 

3 Answers, 1 is accepted

Sort by
0
Jonatan
Top achievements
Rank 1
answered on 03 Dec 2015, 09:30 AM

There are more threads related to Uploading files and binding them to grid rows.

What seems to be lacking is a project example of how to handle this functionality.

Can someone provide a working project example?

0
Jonatan
Top achievements
Rank 1
answered on 03 Dec 2015, 10:02 AM

I found out my issue.

 Apparantly the value of the databinded html field was not updated to the model before I manually triggered the 'Change' Event on the htmleditor. here is the code:

 

@model BlueWebApp.Models.Note
 
<div style="height: 100px;">
     
        @Html.HiddenFor(model => model.NoteID)
        <br />
 
        @Html.HiddenFor(model => model.NoteText)
       
</div>
<div>
    @(Html.Kendo().Upload()
         .Name("files")
         .Events(events => events.Success(
         @<text>
    function(e) {
        $('#NoteText').val(e.response.fileName);
        $('#NoteText').trigger('change')  <!-- Manually Trigger Change Event -->
    }
        </text>))
         .Multiple(false)
         .Async(a => a.Save("Save", "Note")
                      .Remove("Remove", "Note")
                      .AutoUpload(true)
        )
 
)
</div>
<br />

0
Dimiter Madjarov
Telerik team
answered on 03 Dec 2015, 10:02 AM

Hello Jonatan,

Your implementation is correct. A small part missing is that the change event of the hidden input should be triggered. This notifies the model for the modified field.
E.g.

$('#test').val(e.response.fileName).trigger("change");

The complete approach is demonstrated in the following example project.

Regards,
Dimiter Madjarov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Upload
Asked by
Jonatan
Top achievements
Rank 1
Answers by
Jonatan
Top achievements
Rank 1
Dimiter Madjarov
Telerik team
Share this question
or