model view controller - Krajee bootstrap-fileinput with Mvc razor -
i want use krajee bootstrap-fileinput (http://plugins.krajee.com/file-input) mvc razor, please me out process to upload images server , json result actionresult.
i have included required js , css files in view page , added line
<input id="input-702" name="kartik-input-702[]" type="file" multiple="true" class="file-loading">
and script
$("#input-702").fileinput({ uploadurl:"@url.action("upload","home")", uploadasync: true, minfilecount: 1, maxfilecount: 5, overwriteinitial: false, initialpreview: "", initialpreviewconfig:"", uploadextradata: "" });
this line getting formatted , showing drag , drop effect , select file button.the file selection , thumbnail creation working on upload action there (fileinput,js) function "ajaxsubmit" use post content homecontroller actionresult "upload".
ajaxsubmit: function (fnbefore, fnsuccess, fncomplete, fnerror) { var self = this, settings; self.uploadextra(); settings = $.extend({ xhr: function () { var xhrobj = $.ajaxsettings.xhr(); return self.initxhr(xhrobj, 98); }, url: self.uploadurl, type: 'post', datatype: 'json', data: self.formdata, cache: false, processdata: false, contenttype: false, beforesend: fnbefore, success: fnsuccess, complete: fncomplete, error: fnerror }, self.ajaxsettings); self.ajaxrequests.push($.ajax(settings)); },
now want save files server not uploaded using actionresult , pass value js. how retrieve formdata , process.??
i trying find solution above problem , found one. able save file @ server location controller unfortunately not send json response controller javascript.
saving image using controller action :
[httppost] public actionresult upload() { foreach (string item in request.files) { httppostedfilebase file = request.files[item] httppostedfilebase; string filename = file.filename; string uploadpath = "~/images/"; if (file.contentlength == 0) continue; if (file.contentlength > 0) { string path = path.combine(httpcontext.request.mappath(uploadpath), filename); string extension = path.getextension(file.filename); file.saveas(path); } } return json(""); }
to implement delete button have send data server in asynchronous mode json array object eg.
initialpreview: [ '<img src='/images/desert.jpg' class='file-preview-image' alt='desert' title='desert'>', ], initialpreviewconfig: [ { caption: 'desert.jpg', width: '120px', url: '/localhost/avatar/delete', key: 100, extra: {id: 100} } ]
can me out create json array object in controller , send response object.???
Comments
Post a Comment