Jquery passing data to ajax function in mvc4

Sajith

I have developed ASP.NET MVC4 File upload it is working fine but i have one problem i need to passing parameter Folderid to controller but unfortunately i cant get folderId in controller. could you please help me as soon as possible

My code below

$(document).ready(function () {

        var Folderid = "ab";     

        $('#fileupload').fileupload({
            dataType: 'json',
            url: '/Home/UploadFiles',
            autoUpload: true,
             data: { name: Folderid  },
            done: function (e, data) {
                if (data.result.name == '') {
                    $('.file_name').html('Please Upload valid image...');
                    $('.progress .progress-bar').css('width', 0 + '%');

                }
                else {
                    $('.file_name').html("Uploaded Successfully..[ " + data.result.name + " ]");
                }

            }
        }).on('fileuploadprogressall', function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('.progress .progress-bar').css('width', progress + '%');
        });
    }); 

My controller code below

[HttpPost]
        public ContentResult UploadFiles(string name)
        {

            string FolderId = name;

            var r = new List<UploadFilesResult>();               
            foreach (string file in Request.Files)
            {
                var allowedExtensions = new[] { ".jpg", ".jpeg", ".bmp", ".icon" };

                HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                if (hpf.ContentLength == 0)
                    continue;
                if (!allowedExtensions.Contains(System.IO.Path.GetExtension(hpf.FileName).ToString()))
                {
                    r.Add(new UploadFilesResult()
                    {
                        Name = "",
                        Length = 0,
                        Type = ""

                    });
                }
                else
                {
                    string savedFileName = Path.Combine(Server.MapPath("~/Upload"), Path.GetFileName(hpf.FileName));
                    hpf.SaveAs(savedFileName);
                    r.Add(new UploadFilesResult()
                    {
                        Name = hpf.FileName,
                        Length = hpf.ContentLength,
                        Type = hpf.ContentType
                    });
                }
            }
            return Content("{\"name\":\"" + r[0].Name + "\",\"type\":\"" + r[0].Type + "\",\"size\":\"" + string.Format("{0} bytes", r[0].Length) + "\"}", "application/json");
        }
ChrisSwires

Edit Perhaps try changing data to formData in the fileupload call like so:

formData: { name: Folderid  },

Taken from here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Passing data with jquery ajax

From Dev

Jquery AJAX not passing "POST" data

From Dev

Jquery AJAX not passing "POST" data

From Dev

MVC4 Ajax jQuery 2

From Dev

Passing data to a controller with $.ajax (MVC 4)

From Dev

Data inserting using jquery, AJAX in ASP.NET MVC4?

From Dev

MVC4 - When Passing Complex model to the Controller using Ajax

From Dev

jQuery Ajax passing response variable to function

From Dev

Passing data outside ajax call, jQuery

From Dev

Ajax JQuery Passing Data to POST method

From Dev

Passing data outside ajax call, jQuery

From Dev

Data not passing via JQuery AJAX request

From Dev

jQuery AJAX POST not passing data to a PHP script

From Dev

How to call error function in $.ajax with c# MVC4?

From Dev

Json not parsing correctly from jQuery AJAX call in MVC4

From Dev

MVC4 ajax call and return data properly

From Dev

passing multiple form data to a jquery function

From Dev

Jquery Ajax function returning no data

From Dev

Highlight selected tab using jquery function in mvc4 project

From Dev

Sending Json data to @Html.Actionlink() in Jquery in MVC4

From Dev

Unable to append data to table in jquery with mvc4

From Dev

Passing parameters to a function in Ajax

From Dev

Passing parameters to a function in Ajax

From Dev

jQuery ajax returning 404 error when passing URL as post data

From Dev

Passing variable data between jQuery and PHP using AJAX shorthand

From Dev

Passing form data to controller using AJAX and jquery with Codeigniter

From Dev

jQuery ajax returning 404 error when passing URL as post data

From Dev

input value data is not passing using jquery/ajax to Php

From Dev

JQuery ajax not working when passing ip address in data with parameters

Related Related

HotTag

Archive