Again, asking MVC Noob questions. Forgive my lack of experience.
I have a situation where I use the MVC route to return a large XML file. Sometimes it can be very big. I am currently using StringBuilder to generate the XML output I want, and then return it as follows:
var sb = new StringBuilder(); XmlObject.WriteXml(sb); return Content(sb.ToString(), "text/xml", Encoding.UTF8);
What I'm using is that (for various reasons) an XML blog can take quite some time.
Inside the XmlObject.WriteXml () method, there are tons of calls to other small methods that output XML bits and fragments as they are called, so I START building an XML line right away, it will take some time to finish. Each of these methods takes a StringBuilder as an argument, so it can create one and then pass it around the place using sb.Append () in each small method to build the final XML block.
OK, so I would like to start returning something to the client as soon as the line starts building. In Webforms, I would replace all StringBuilder parameters with HttpResponse parameters and use HttpResponse.Write () instead of StringBuilder.Append () like this:
this.Response.BufferOutput = false; XmlObject.WriteXml(Response);
Then, when each small piece of XML has been recorded in response, the text will be sent to the client.
The problem I am facing is that the ActionResult must have a return statement. I do not know how to treat in a similar fasion using the MVC route and ActionResult. Maybe I need to use something other than ActionResult?
Thanks everyone!
source share