Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
<pre>@(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:



JavaScript
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:


VB
'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...
Posted

1 solution

I solved it... I just changed my javascript function


JavaScript
function statusAndLocking_DownloadFile(projectAttachmentID) {
        var finUrl = "/StatusAndLocking/GetFileByProjectAttachmentID/" + projectAttachmentID;
        var win = window.open(finUrl);
        win.focus();
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900