How do you set the content type for a WebMatrix/Ra

2019-04-03 14:59发布

I'd like to return some XML instead of HTML in my WebMatrix cshtml file? How do you change the content type header?

3条回答
冷血范
2楼-- · 2019-04-03 15:11

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

@{
  Response.ContentType = "application/xml";
}
... xml here ...
查看更多
混吃等死
3楼-- · 2019-04-03 15:12

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();
}
查看更多
可以哭但决不认输i
4楼-- · 2019-04-03 15:17

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>
查看更多
登录 后发表回答