How do you set the content type for a WebMatrix/Razor Response?

白昼怎懂夜的黑 提交于 2019-12-03 22:44:38

Use the Response.ContentType property at the top of your .cshtml file then include the XML in the content of the view:

@{ 
   Response.ContentType = "application/xml";
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>415-123-4567</Dial>
</Response>

At the top of your Razor file, set the ContentType of the Response object:

@{
  Response.ContentType = "application/xml";
}
... xml here ...

If you are using ASP.NET MVC, you can choose to make the change in your action method in the controller, like so:

public ActionResult MyAction() {
    Response.ContentType = "text/xml";
    return View();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!