tags:

views:

40

answers:

1

In my ASP.net c# MVC project, I want to get raw XML generated from reading DB.

I am getting XML response back, but problem is that my complete XML shows as plain string within my string

What should I change to make this response a well formated XML output?

Below is what I have got

public override void ExecuteResult(ControllerContext context)
{
    if (this.objectToSerialize != null)
    {
        context.HttpContext.Response.Clear();

        var xs = new System.Xml.Serialization.XmlSerializer(this.objectToSerialize.GetType());

        context.HttpContext.Response.ContentType = "text/xml";

        context.HttpContext.Response.ContentEncoding = UTF8;

        xs.Serialize(context.HttpContext.Response.Output, this.objectToSerialize);
    }
}
A: 

Are you sure that you are getting plain text back? Many browsers only show the text inside the XML when XML is received.

If you in your browser view source (IE8: right-click and select View Source, similar in Firefox and Chrome), is it XML or is it still plain text?

Andreas Paulsson