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.

3
  • 2
    Whats the signature of your POST method? Commented Feb 3, 2015 at 10:37
  • @StephenMuecke [HttpPost] public string GetAdminUploadData (){return string.empty} Commented Feb 3, 2015 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 Commented Feb 3, 2015 at 13:14

1 Answer 1

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"]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.