Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4082426
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:11:10+00:00 2026-05-20T18:11:10+00:00

I have a Controller method that needs to accept multipart/form-data sent by the client

  • 0

I have a Controller method that needs to accept multipart/form-data sent by the client as a POST request. The form data has 2 parts to it. One is an object serialized to application/json and the other part is a photo file sent as application/octet-stream. I have a method on my controller like this:

[AcceptVerbs(HttpVerbs.Post)]
void ActionResult Photos(PostItem post)
{
}

I can get the file via Request.File without problem here.However the PostItem is null.
Not sure why? Any ideas

Controller Code:

/// <summary>
/// FeedsController
/// </summary>
public class FeedsController : FeedsBaseController
{
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Photos(FeedItem feedItem)
    {
        //Here the feedItem is always null. However Request.Files[0] gives me the file I need  
        var processor = new ActivityFeedsProcessor();
        processor.ProcessFeed(feedItem, Request.Files[0]);

        SetResponseCode(System.Net.HttpStatusCode.OK);
        return new EmptyResult();
    }

}

The client request on the wire looks like this:

{User Agent stuff}
Content-Type: multipart/form-data; boundary=8cdb3c15d07d36a

--8cdb3c15d07d36a
Content-Disposition: form-data; name="feedItem"
Content-Type: text/xml

{"UserId":1234567,"GroupId":123456,"PostType":"photos",
    "PublishTo":"store","CreatedTime":"2011-03-19 03:22:39Z"}

--8cdb3c15d07d36a
Content-Disposition: file; filename="testFile.txt"
ContentType: application/octet-stream

{bytes here. Removed for brevity}
--8cdb3c15d07d36a--
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:11:11+00:00Added an answer on May 20, 2026 at 6:11 pm

    What does the FeedItem class look like? For what I see in the post info it should look something like:

    public class FeedItem
    {
        public int UserId { get; set; }
        public int GroupId { get; set; }
        public string PublishTo { get; set; }
        public string PostType { get; set; }
        public DateTime CreatedTime { get; set; }
    }
    

    Otherwise it will not be bound. You could try and change the action signature and see if this works:

    [HttpPost] //AcceptVerbs(HttpVerbs.Post) is a thing of "the olden days"
    public ActionResult Photos(int UserId, int GroupId, string PublishTo
        string PostType, DateTime CreatedTime)
    {
        // do some work here
    }
    

    You could even try and add a HttpPostedFileBase parameter to your action:

    [HttpPost]
    public ActionResult Photos(int UserId, int GroupId, string PublishTo
        string PostType, DateTime CreatedTime, HttpPostedFileBase file)
    {
        // the last param eliminates the need for Request.Files[0]
        var processor = new ActivityFeedsProcessor();
        processor.ProcessFeed(feedItem, file);
    
    }
    

    And if you’re really feeling wild and naughty, add HttpPostedFileBase to FeedItem:

    public class FeedItem
    {
        public int UserId { get; set; }
        public int GroupId { get; set; }
        public string PublishTo { get; set; }
        public string PostType { get; set; }
        public DateTime CreatedTime { get; set; }
        public HttpPostedFileBase File { get; set; }
    }
    

    This last code snippet is probably what you want to end up with, but the step-by-step breakdown might help you along.

    This answer might help you along in de right direction as well: ASP.NET MVC passing Model *together* with files back to controller

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following this post and the other posts that it links to, I have successfully
I have a simple Rails 3 app: no models, one view and one controller
I have a simple Partial View that I would like to automatically call a
The issue I have a popup button ( NSPopUpButton ) that is bound to
I have a users model and a book model. Users can read books (as
I have a Partial View with two opposite ActionLinks inside: <div id=divStatus> @if (IsAuthenticated)
The goal is to update a property of staff while choosing a new manager
A few general questions to those who are well-versed in developing web-based applications. Question
I am building an ASP.Net MVC 3 application with Entity Framework 4. When the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.