I am trying to pass the Kendo Grid row data to the partial view rendered through Kendo popup window.
In the partial view, an image file can be uploaded for the row record. This part is asynchronous and separate from the row edit. I have got uploading and saving image working, but I need to get the ID of the row so that I can save the image file for that record.
Also, I need to pass the image data to the partial view and display it later on once there is any.
How do I pass data to the partial view(Kendo popup window) from the Kendo Grid perfectly on the client side since the data is already in the Kendo Grid dataSource
?
JS:
$("#manageLostPropertiesGrid").kendoGrid({
dataSource: lostPropertyDataSource,
pageable: true,
height: 550,
toolbar: ["create"],
columns: [
{
command: { text: "View", click: showPhoto },
title: "Photo",
filterable: false, sortable: false, width: 100,
},
{ field: "PropertyName", title: "Property Name", width: "150px" },
{ field: "CategoryName", title: "Category", editor: propertyCategoryList, width: "150px" },
{ field: "PropertyDescription", title: "Description", width: "200px" },
{
field: "FoundDate", type: "date", title: "Found Date", format: "dd/MM/yyyy",
template: "#= kendo.toString(kendo.parseDate(FoundDate, 'dd-MM-yyyy'), 'dd/MM/yyyy') #", width: "130px"
},
{ field: "FoundLocation", title: "Found Location", width: "120px" },
{ command: ["edit", "destroy"], title: " ", width: "250px" }],
editable: "popup"
}).data("kendoGrid");
// Pop-up window for photo view/upload
wnd = $("#photo-window")
.kendoWindow({
content: {
url: "ImageUploader",
},
title: "Image Uploader",
modal: true,
visible: false,
resizable: true,
width: 750,
height: 500
}).data("kendoWindow");
photoTemplate = kendo.template($("#template").html());
function showPhoto(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
wnd.center().open();
}
Partial View:
<div id="example" class="k-content">
<div class="demo-section k-content wide">
<div class="wrapper">
<div id="products"></div>
<div class="dropZoneElement">
<div class="textWrapper">
<p>Add Image</p>
<p class="dropImageHereText">Drop image here to upload</p>
</div>
</div>
</div>
</div>
<input name="files" id="files" type="file" />
<script type="text/x-kendo-template" id="template">
<div class="product"></div>
</script>
<script>
$(function () {
var template = kendo.template($("#template").html());
var initialFiles = [];
$("#products").html(kendo.render(template, initialFiles));
$("#files").kendoUpload({
async: {
saveUrl: "save?id=" + "1",//Need the row Id here
removeUrl: "remove",
autoUpload: true
},
multiple: false,
validation: {
allowedExtensions: [".jpg", ".jpeg", ".png", ".bmp", ".gif"]
},
success: onSuccess,
dropZone: ".dropZoneElement"
});
function onSuccess(e) {
if (e.operation == "upload") {
var file = e.files[0].rawFile;
if (file) {
var reader = new FileReader();
reader.onloadend = function () {
$("#products").empty().append("<div class='product'><img src=" + this.result + " /></div>");
};
reader.readAsDataURL(file);
}
}
if (e.operation == "remove") {
$("#products").empty();
}
}
});
</script>
Id
of the row to the partial view. If I make a server call, how does the server side know which row did I click and pass to the partial view at the same time? – Salomon Zhang