Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 397
John Sheehan Avatar asked Jul 06 '10 22:07

John Sheehan


2 Answers

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>
like image 190
John Sheehan Avatar answered Oct 04 '22 02:10

John Sheehan


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

@{
  Response.ContentType = "application/xml";
}
... xml here ...
like image 26
Mike Avatar answered Oct 04 '22 03:10

Mike