ASP.NET MVC和text / xml内容types
我想从一个动作返回一个View(),并且得到的响应应该有一个text / xml的内容types,而不是默认的文本/ html。
我尝试了以下,但没有成功:
Response.ContentType = "text/xml"; return View();  我知道你可以通过返回ContentResult指定内容types,但是这不会渲染我的视图。 
 我希望我不需要渲染视图的string,然后使用return Content() ,所以我可能忽略了一些简单的方法。 
 <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" ContentType="text/xml" %> 
你需要渲染string。 要返回text / xml,请执行以下操作:
 return new ContentResult { ContentType = "text/xml", Content = UTF8.GetString(yourXmlString), ContentEncoding = System.Text.Encoding.UTF8 }; 
用户控件(ASCX)不接受ContentType =“text / xml”。
解:
 public ActionResult xxx() { Response.ContentType = "text/xml"; return View("xxx.ascx"); } 
您需要一个不会覆盖事物并生成HTML的视图,包括它自己的上下文types。
 自定义视图可以直接呈现给Response.Write(请参阅Reflector中的JsonResult ,以获得与您需要的类非常相似的类)。 
 要呈现没有中间string的XML,请将您的XML保存到通过Response.Output创build的XmlWriter 。 
你有没有尝试从代码隐藏页面中的视图的预渲染方法设置response.content? 这显然假设你正在使用webform视图引擎