开发者

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

开发者 https://www.devze.com 2023-01-06 03:01 出处:网络
I\'d like to return some XML instead of HTML in my WebMatrix cshtml file? 开发者_开发知识库How do you change the content type header?Use the Response.ContentType property at the top of your .cshtml fi

I'd like to return some XML instead of HTML in my WebMatrix cshtml file? 开发者_开发知识库How do you change the content type header?


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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号