ASP.NET MVC and text/xml content type ASP.NET MVC and text/xml content type xml xml

ASP.NET MVC and text/xml content type


<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage"     ContentType="text/xml" %>


You need to render the string. To return text/xml do the following:

return new ContentResult {    ContentType = "text/xml",    Content = UTF8.GetString(yourXmlString),    ContentEncoding = System.Text.Encoding.UTF8}; 


Users control (ASCX) doesn't accept ContentType="text/xml".

Solution:

public ActionResult xxx()  {     Response.ContentType = "text/xml";     return View("xxx.ascx");  }