ASP.NET MVC和文本/ xml内容类型 [英] ASP.NET MVC and text/xml content type
本文介绍了ASP.NET MVC和文本/ xml内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从一个动作返回查看(),并将得到的反应应该有文本/ XML,而不是默认的text / html的内容类型。
我曾尝试以下,没有成功:
Response.ContentType =文/ XML;
返回查看();
我知道,你可以通过返回指定内容类型 ContentResult类型
,但是,这并不使我的看法。
我希望我不需要渲染视图为一个字符串,然后使用返回内容()
,所以我可能俯瞰一些简单的方法。
解决方案
<%@页面语言=C#继承=System.Web.Mvc.ViewPage
的ContentType =文/ XML%GT;
I want to return a View() from an action, and the resulting response should have a content type of text/xml instead of the default text/html.
I have tried the following, with no success:
Response.ContentType = "text/xml";
return View();
I know that you can specify the content type by returning ContentResult
, but that doesn't render my View.
I'm hoping I don't need to render the view to a string then use return Content()
, so I'm probably overlooking some easy way.
解决方案
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage"
ContentType="text/xml" %>
这篇关于ASP.NET MVC和文本/ xml内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文