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 7972669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:55:45+00:00 2026-06-04T07:55:45+00:00

I am creating an ASP.NET MVC3 restful web service to allow reports to be

  • 0

I am creating an ASP.NET MVC3 restful web service to allow reports to be uploaded from a set of servers. When a new report is created, I want the client app to do a PUT to

  • http://MyApp/Servers/%5BServerName%5D/Reports/%5BReportTime%5D

passing the content of the report as XML in the body of the request.

My question is: how do I access the content of the report in my controller? I would imagine that it is available somewhere in the HttpContext.Request object but I am reluctant to access that from my controller as it is not possible(?) to unit test that. Is it possible to tweak the routing to allow the content to be passed as one or more parameters into the controller method? The outcome needs to be RESTful, i.e. it has to PUT or POST to a URL like the one above.

Currently my routing is:

routes.MapRoute(
    "SaveReport",
    "Servers/{serverName}/Reports/{reportTime",
    new { controller = "Reports", action = "Put" },
    new { httpMethod = new HttpMethodConstraint("PUT") });

Is there any way to modify this to pass content from the HTTP request body into the controller method?
The controller method is currently:

public class ReportsController : Controller
{
    [HttpPut]
    public ActionResult Put(string serverName, string reportTime)
    {
        // Code here to decode and save the report
    }
}

The object I am trying to PUT to the URL is:

public class Report
{
    public int SuccessCount { get; set; }
    public int FailureOneCount { get; set; }
    public int FailureTwoCount { get; set; }
    // Other stuff
}

This question looks similar but doesn’t have any answer.
Thanks in advance

  • 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-06-04T07:55:46+00:00Added an answer on June 4, 2026 at 7:55 am

    Seems like you just need to use the standard ASP.NET MVC model binding capability with the slight wrinkle that you would doing an HTTP PUT instead of the more common HTTP POST. This article series has some good samples to see how model binding is used.

    Your controller code would then look like:

    public class ReportsController : Controller
    {
        [HttpPut]
        public ActionResult Put(Report report, string serverName, string reportTime)
        {
            if (ModelState.IsValid)
            {
                // Do biz logic and return appropriate view
            }
            else
            {
                // Return invalid request handling "view"
            }
        }
    }
    

    EDIT: ====================>>>

    Jon added this code to his comment as part of the fix so I added it to the answer for others:

    Create a custom ModelBinder:

    public class ReportModelBinder : IModelBinder
    {
        public object BindModel(
            ControllerContext controllerContext,
            ModelBindingContext bindingContext)
        {
            var xs = new XmlSerializer(typeof(Report));
            return (Report)xs.Deserialize(
                controllerContext.HttpContext.Request.InputStream);
        }
    }
    

    Modify the Global.asax.cs to register this model binder against the Report type:

    ModelBinders.Binders[typeof(Report)] = new Models.ReportModelBinder();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a new web application using ASP.NET MVC3 Razor and HTML 5.
I'm creating a project from the book Sanderson Pro ASp.net mvc3. But I have
When creating a new ASP.NET MVC3 application, in the default project there is a
When creating a new asp.net mvc3 app you get the logon and register form
I would like to build a new web application using ASP.NET MVC3 and MongoDB.
I'm creating a new asp.net MVC3 app in which in user table I do
I'm creating a new project, asp.net mvc3 with Razor, and wanting to turn the
I am creating an ASP.NET MVC3 application using NHIBERNATE. I have a base class
I am creating a ASP.Net Web API to expose an existing database for use
I'm looking at creating a custom membership provider in ASP.Net MVC3 and am struggling

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.