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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:34:05+00:00 2026-05-19T13:34:05+00:00

MVC newbie here: I’ve more or less worked out the page navigation aspect of

  • 0

MVC newbie here:

I’ve more or less worked out the page navigation aspect of MVC. But let’s say I don’t want to navigate to a View, but rather I want to get a response out of the web site, e.g. by sending a request to http://mysite.com/Services/GetFoo/123 I want to make a database request to select a Foo object with ID 123 and return it serialized as XML.

How do you do that?

  • 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-19T13:34:05+00:00Added an answer on May 19, 2026 at 1:34 pm

    I would write a custom action result:

    public class XmlResult : ActionResult
    {
        private readonly object _data;
        public XmlResult(object data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            _data = data;
        }
    
        public override void ExecuteResult(ControllerContext context)
        {
            // You could use any XML serializer that fits your needs
            // In this example I use XmlSerializer
            var serializer = new XmlSerializer(_data.GetType());
            var response = context.HttpContext.Response;
            response.ContentType = "text/xml";
            serializer.Serialize(response.OutputStream, _data);
        }
    }
    

    and then in my controller:

    public ActionResult GetFoo(int id)
    {
        FooModel foo = _repository.GetFoo(id);
        return new XmlResult(foo);
    }
    

    And if this return new XmlResult(foo); feels ugly to your eyes, you could have an extension method:

    public static class ControllersExtension
    {
        public static ActionResult Xml(this ControllerBase controller, object data)
        {
            return new XmlResult(data);
        }
    }
    

    and then:

    public ActionResult GetFoo(int id)
    {
        FooModel foo = _repository.GetFoo(id);
        return this.Xml(foo);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, one more newbie here, just playing around with .NET MVC. My main task
I am a newbie with Spring MVC but I'm quite impressed with its capabilities.
I'm a newbie in ASP.net MVC 3. I'm trying to do something trivial, but
I'm a newbie about ASP.NET MVC 3, but I have a simple question. Is
AJAX newbie here! At the moment in my ASP.NET MVC web app my AJAX
I'm an ASP.NET MVC newbie, but have used many Model-View-Controller frameworks previously. I recently
MVC newbie here again! I have two lists in my controller. IList<Cars> allCars =
MVC newbie question re binders. Supposing I have two strongly typed partial actions that
I am an MVC newbie. As far as I can tell: Controller : deals
Ok, I'm an MVC newbie coming from a webforms background, so please excuse any

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.