MVC: ContentResult

Please see my other MVC articles.

Returning different types of content.

MVC provide flexibility when answering requests for resources by supporting different types of content.
In this article, I will illustrate the use of the ContentType to return plain text and XML.

Here I have a simple example of how a Controller may return plain text to the browser.
Notice the second parameter I give the Content() method – “text/plain.”


When calling the Controller, you’ll notice that plain text is returned – content with no HTML tags.



In the next example, I’ve created a Controller that returns an example XML document for sales associates.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s