I know this is an old question, but I found it when I was looking for a solution to this problem. Since no one has an easy solution, here is mine:
I was able to fix this using a partial view instead of the usual view. I believe the problem boils down to the layout, even if you set it to zero, it still seems like it is adding an empty first line. @ {} Declares an empty string, so you must move it to the bottom of your view.
So, just add a partial view, and your controller will return a partial view as such:
public ActionResult GenerateXML() { return PartialView("_XML"); }
Then in your partial view, you will need to configure it as follows (using @ {} below):
@model string <?xml version="1.0" encoding="UTF-8" ?> <response> <message>@Model</message> </response> @{ Response.ContentType = "text/xml";}
This will lead to the HTML source:
<?xml version="1.0" encoding="UTF-8" ?> <response> <message>Response Message</message> </response>
I hope this helps others facing this issue.
Joeyzero
source share