function tableRowsViewModel() { var self = this; self.tableRows = ko.observableArray(); self.arrayNew = ko.observableArray(); self.addNewRow = function () { self.tableRows.push(new tableRow(Math.random().toString(36).substring(9), '', '', [])); } self.save = function () { $.post("/Home/Save", { obj: ko.toJSON(this.tableRows()) }, function (data) { console.log(JSON.stringify(this.tableRows())); }); }, self.select = function () { $('#inputFile').attr("data", this.Guid()); var Gid = this.Guid() var findItem = ko.utils.arrayFilter(vm.tableRows(), function (item) { return (item.Guid() === Gid); }); self.arrayNew.removeAll(); findItem[0].FileList().forEach(function (item) { self.arrayNew.push(item); }); var dialog dialog = $("#dialog-form").dialog({ autoOpen: false, height: 300, width: 350, modal: true, buttons: { Ok: function () { dialog.dialog("close"); } } }); dialog.dialog("open");
self.remove = function (item) { if (!confirm("Do you want to delete")) { return false; } $.post("/Home/Remove", { obj: ko.toJSON(item) }, function (data) { self.tableRows.remove(item); });
} },
self.selected = function (data, event) { $('#progressDiv').progressbar({ value: 10, max: 100, change: function (e) { $('.progress-label').text($('#progressDiv').progressbar("value") + "%"); } });
var path = $("#inputFile").val(); var formData = new FormData(); var file = document.getElementById("inputFile").files[0]; formData.append("file", file);
var divElem = $('#progressDiv');
$.ajax({ type: "POST", url: '/Home/UploadImage', data: formData, dataType: 'json', contentType: false, processData: false, success: function (response) { var findItem = ko.utils.arrayFilter(vm.tableRows(), function (item) { return (item.Guid() === $("#inputFile").attr("data")); }); console.log(response.Extention); findItem[0].FileList.push(new fileModel(response.FileName, response.Extention, response.FilePath, response.Guid)); self.arrayNew.push(new fileModel(response.FileName, response.Extention, response.FilePath, response.Guid)); $("#progressDiv").progressbar("destroy"); $('.progress-label').text(''); $("#inputFile").val(''); }, xhr: function () { var xhr = $.ajaxSettings.xhr(); if (xhr.upload) { xhr.upload.addEventListener('progress', function (evt) { var percent = Math.floor((evt.loaded / evt.total) * 100); divElem.progressbar("value", percent);
}; self.RemoveImage = function (file) { if (!confirm("Do you want to delete")) { return false; } var Gid = $('#inputFile').attr("data"); var findItem = ko.utils.arrayFilter(vm.tableRows(), function (item) { return (item.Guid() === Gid); });
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Script.Serialization; using System.Web.UI.WebControls;
namespace ForceLMS_DEMO.Controllers { public class HomeController : Controller { public ActionResult Index() { return View(); }
[HttpPost] public JsonResult Save(string obj = null) { JavaScriptSerializer Serializer = new JavaScriptSerializer(); var selected = Serializer.Deserialize<List<tableRow>>(obj).ToList();
foreach (tableRow re in selected) { foreach (FileList fe in re.FileList) {
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Hi '
we are providing code shown is below. I hope to help you.
Index.cshtml