Introduction
In this article we will see how to use content results in a controller in MVC.Step 1Create a MVC project from the "Empty" template.Right-click on "Controllers" and select "Add" >> "Controller...".Step 2Select "MVC 5 Controller - Empty" to add an empty controller.Click on the "Add" button.Step 3Name the controller as in the following:And it will add an action result method in the controller.Step 4ContentResult represents a user-defined content type. It is inherited from ActionResult. ContentResult has the following three properties:Content that we want to render on browserContentEncoding that defines the encoding of the contentContentType that informs the browser about the content like "text/plain", "text/html", "application/json" and so on.Here the ContentResult method returns an object of ContentResult. In the first parameter we pass the content that we want to render on the browser. The second parameter is of ContentType and the third one is content encoding.Step 5Run the project and you will see, content is rendered in the browser<< Day 8 Day 10 >>
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: