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:
Here's the javascript code:
Here's the controller:
Thank you in advance for your kind help.
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.