1

I need to upload files and some other data, for which I used bellow code

HTML:

<intut type='file' id='file1'>
<intut type='file' id='file2'>

javascript:

var data = new FormData(),
    categories = ['node.js','redis'],
    roles = ['admin','HR'];
data.Append ($('#file1').Files[0].name, $('#file1').Files[0]);
data.Append ($('#file2').Files[0].name, $('#file2').Files[0]);
data.Append ('category', 'categories');
data.Append ('role', 'roles');

   $.ajax({
        url: baseaddress + 'DocRepo/GetAdminUploadData',
        type: 'Post',
        data: data,
        cache: false,
        dataType: 'json',
        async: false,
        contentType: false,
        processData: false,
        success: function (data) {
        },
        error: function (data) {
        }
    });

From here I have an action method in my MVC Controller (not webapi) GetAdminUploadData where I need to collect all data(files, category and roles) how can do it.

Rahul Chakrabarty
  • 2,149
  • 7
  • 39
  • 70
  • 2
    Whats the signature of your POST method? –  Feb 03 '15 at 10:37
  • @StephenMuecke `[HttpPost] public string GetAdminUploadData (){return string.empty}` – Rahul Chakrabarty Feb 03 '15 at 13:04
  • Your method is not even an ActionResult, and it does not have any parameters. Add parameters for the values your posting e.g. `string category, string role`, but since you appear to be dynamically naming the files you will need to get the files from `Request.Files` although it would be much easier if you had parameter for `HttpPostedFileBase file1, HttpPostedFileBase file2` –  Feb 03 '15 at 13:14

1 Answers1

0

Assuming that you are only looking for how to get the non-file items (as the title says ... although is not mentioned in the body of the question) and that the server code is C# (as your note from 3-feb-15 hints) I'd say this question is a duplicate of and answered by: How can retrieve string formData js in c#.

Namely: HttpContext.Current.Request.Form["KEY"]

Community
  • 1
  • 1
steve
  • 1,021
  • 1
  • 14
  • 29