ListView not passing Model to EditorTemplate

2 posts, 1 answers
  1. Steton
    Steton avatar
    4 posts
    Member since:
    Jul 2006

    Posted 12 Sep 2013 Link to this post

    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?
  2. Answer
    Steton
    Steton avatar
    4 posts
    Member since:
    Jul 2006

    Posted 13 Sep 2013 Link to this post

    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()
    )
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top