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

ListView not passing Model to EditorTemplate

1 Answer 154 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Steton
Top achievements
Rank 1
Steton asked on 12 Sep 2013, 10:41 PM
I have a list view that supports viewing and deleting attached files.  That works just fine.  The problem I am having is when I try to add a new file to the list.  I have a custom editor template for the AttachedFile object, but when the editor runs the Model passed into it is empty.  I have specified a default value on the field that I need to access in editor template, which I would assume would be passed to the editor.  

Here is my ListView:
@(Html.Kendo().ListView<AttachedFile>()
    .Name("attachedFilesListView")
    .TagName("div")
    .ClientTemplateId("attachedFilesTemplate")
    .DataSource(dataSource => dataSource
        .Model(model => {
            model.Id(f => f.AttachedFileID);
            model.Field(f => f.EntityTableKey).DefaultValue(Model.CorrectiveActionItemID);
        })
        .Read(read => read.Action("Files_Read", "CorrectiveActionItem", new { correctiveActionItemId = Model.CorrectiveActionItemID }))
        .Destroy(destroy => destroy.Action("Files_Delete","CorrectiveActionItem"))
        .PageSize(4)
    )
    .Pageable()
    .Editable()
)
Here is my EditorTemplate:
@model AttachedFile
 
@(Html.Kendo().Upload()
    .Name("files")
    .Async(a => a.Save("SaveFile", "CorrectiveActionItem", new { correctiveActionItemId = Model.EntityTableKey })
    .AutoUpload(true))
)
The problem is the Model.EntityTableKey is empty in the editor.  

What am I doing wrong?  Shouldn't the default value be passed to the editor template?

1 Answer, 1 is accepted

Sort by
0
Accepted
Steton
Top achievements
Rank 1
answered on 13 Sep 2013, 05:02 PM
I solved my own problem.  The issue was that since I was using that view as a client template, I needed to do client-side binding and call ToClientTemplate on the Kendo Control.  

Here is the working version of my Editor Template:

@(Html.Kendo().Upload()
    .Name("files")
    .Async(a => a
        .Save("SaveFile", "CorrectiveActionItem", new { correctiveActionItemId = "#=EntityTableKey#" })
        .Remove("RemoveFile", "CorrectiveActionItem", new { correctiveActionItemId = "#=EntityTableKey#" })
        .AutoUpload(true))
    .ToClientTemplate()
)
Tags
ListView
Asked by
Steton
Top achievements
Rank 1
Answers by
Steton
Top achievements
Rank 1
Share this question
or