8 Eylül 2012 Cumartesi

asp.net mvc de jQuery.ajax ile Resim,Dosya(multiupload) Ekleme

http://www.uploadify.com/ ilgili dosyaları indirdikten sonra

<link href="@Url.Content("~/Content/uploadify/uploadify.css")" rel="stylesheet" type="text/css" />

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>

<script src="@Url.Content("~/Content/uploadify/jquery.uploadify.min.js")" type="text/javascript"></script>

<script type="text/javascript">


    jQuery(document).ready(function () {

        var inputName = "file";

        jQuery("#" + inputName).uploadify({

            'hideButton': true,
            'wmode': 'transparent',
            'buttonText':'Seçiniz',
            'swf': '@Url.Content("~/Content/uploadify/uploadify.swf")',
            'uploader': '@Url.Action("Upload","Home")',
            'script': '@Url.Action("Upload", "Home")',
            //'script': '/Home/Upload',
            'fileDataName': inputName,
            'sizeLimit': 38000000,
            'cancelImg': '@Url.Content("~/Content/uploadify/cancel.png")',
            'auto': false,
            'debug': false,
            'multi': true,
            'formData': { 'ID': '2', 'KID': '3' },// Extra parametre göndermek isteyenler için..
            "onUploadStart":function (file) { $("#" + inputName).uploadify("settings", "ID", 'KID', 2); },// Extra parametre göndermek isteyenler için..

onError: function () { alert('some error occurred. Sorry'); },

            onComplete: function (event, queueId, fileObj, response, data) { alert(response); }
        });
    });
</script>

<p>
    <form method="post" enctype="multipart/form-data">
        <p>
            <input type="file" name="file" id="file" />
            <a href="javascript:$('#file').uploadify('upload','*')">Upload Files</a>
        </p>
    </form>
</p>


        [HttpPost]

        public JsonResult Upload(int? ID,int? KID)
        {
            foreach (string file1 in Request.Files)
            {
                var postedFileBase = Request.Files[file1];            
                string filename= postedFileBase.FileName;
                postedFileBase.SaveAs(HttpContext.Server.MapPath("/UserFiles/") + filename);

            }

            return Json(true);
        }



Hiç yorum yok:

Yorum Gönder

Yorum Gönder