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

File download not appearing in pop-up dialog kendo window

2 Answers 263 Views
Window
This is a migrated thread and some comments may be shown as answers.
Silver Lightning
Top achievements
Rank 1
Silver Lightning asked on 06 Aug 2014, 01:58 AM
Hi to all,

Great day...

I would like to ask or is this a bug on kendow window or may be there's something missing on my code.
I'm trying to download a different types of file (.zip, pdf. xlsx, docx, etc).
But when I'm try to click the download link (attachment name link), the data is trying to open on kendo window as garbage.
This file is a byte data type came from SQL Server database..
I use this on pop-up dialog kendo window where there's a kendo grid inside of it.

Here's my code below:

Razor:
@(Html.Kendo().Grid(Of SPIMS.ViewModel.ProjectViewModel.StatusAndLockingEntity)() _
             .Name("gridProjectAttachment") _
             .Columns(Sub(c)
                              c.Bound(Function(p) p.ID).Visible(False)
                              c.Bound(Function(p) p.AttachmentName).Width(300).HtmlAttributes(New With {.class = "gridContentLeft"}).Title("Attachment") _
                                     .ClientTemplate("<a href='javascript:statusAndLocking_DownloadFile(" + "#=ID#" + ")'>" + "#=AttachmentName#" + "</a>")
                              c.Bound(Function(p) p.FileSize).Width(100).HtmlAttributes(New With {.class = "gridBodyAttribute"}).Title("File Size")
                      End Sub) _
             .Sortable(Function(sorting) sorting.AllowUnsort(True)) _
             .Filterable() _
             .Scrollable() _
             .HtmlAttributes(New With {.style = "height:200px;width:470px;"}) _
             .DataSource(Sub(d)
                                 d.Ajax() _
                                 .PageSize(Session(LocalConstant.Ses_GridPageSize)) _
                                 .Model(Sub(model) model.Id(Function(p) p.ID)) _
                                 .Events(Sub(e)
                                                 e.Error("grid_error_handler")
                                         End Sub) _
                                 .ServerOperation(False) _
                                 .Read(Function(read) read.Action("ProjectAttachment_Read", "StatusAndLocking"))
                         End Sub) _
         .Pageable(Function(pageable) pageable _
         .Refresh(True) _
         .PageSizes(True) _
         .ButtonCount(Session(LocalConstant.Ses_GridButtonCount))))

Here's the javascript code:

function statusAndLocking_DownloadFile(projectAttachmentID) {
       var windowAttachment = "#windowAttachment";
       debugger;
       $(windowAttachment).kendoWindow();
       var dialog = $(windowAttachment).data("kendoWindow");
       dialog.refresh(
           {
               url: "/StatusAndLocking/GetFileByProjectAttachmentID",
               data: { id: projectAttachmentID }
           });
   }


Here's the controller:

'Download File
  Function GetFileByProjectAttachmentID(ByVal id As Integer) As FileContentResult
      Dim _repoProject As New ProjectRepository
      Dim _projectAttachment As New ProjectViewModel.StatusAndLockingEntity
      Dim fileData As Byte() = Nothing
      Dim fileName As String = String.Empty
 
      _projectAttachment = _repoProject.StatusAndLocking_GetFileByProjectAttachmentID(id)
 
      If _projectAttachment IsNot Nothing Then
          fileData = _projectAttachment.SystemFile
          fileName = _projectAttachment.AttachmentName
 
 
      End If
 
      Return File(fileData, System.Net.Mime.MediaTypeNames.Application.Octet, fileName)
  End Function


Thank you in advance for your kind help.

2 Answers, 1 is accepted

Sort by
0
Silver Lightning
Top achievements
Rank 1
answered on 06 Aug 2014, 10:26 PM
no reply?
0
Silver Lightning
Top achievements
Rank 1
answered on 07 Aug 2014, 02:52 AM
I solved it, I just changed my javascript function.

function statusAndLocking_DownloadFile(projectAttachmentID) {
        var finUrl = "/StatusAndLocking/GetFileByProjectAttachmentID/" + projectAttachmentID;
        var win = window.open(finUrl);
        win.focus();
    }
Tags
Window
Asked by
Silver Lightning
Top achievements
Rank 1
Answers by
Silver Lightning
Top achievements
Rank 1
Share this question
or