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.”

1-mvc-contentresult

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

2-mvc-contentresult

3-mvc-contentresult

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

4-mvc-contentresult

5-mvc-contentresult

6-mvc-contentresult

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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