In this article I will explain with an example, how to use ContentResult in ASP.Net MVC Razor.
ContentResult return type is used for returning Content i.e. String, XML string, etc. from Controller to View in ASP.Net MVC Razor.
The Controller consists of two Action methods.
Action method for handling GET operation
Inside this Action method, simply the View is returned.
Action method for handling AJAX POST operation
This Action method handles the call made from the jQuery AJAX function from the View.
Note: The following Action method handles AJAX calls and since a String value is returned, the return type is set to ContentResult.
The value of the name parameter along with the Current Date and Time is returned back to the View as a String value.
public class HomeController : Controller
    // GET: Home
    public ActionResult Index()
        return View();
    public ContentResult AjaxMethod(string name)
        string currentDateTime = string.Format("Hello {0}.\nCurrent DateTime: {1}", name, DateTime.Now.ToString());
        return Content(currentDateTime);
The View consists of an HTML TextBox element and a Button. The Button has been assigned a jQuery click event handler and when the Button is clicked a jQuery AJAX called is made to the Controller’s action method.
Note: For more details on using jQuery AJAX in ASP.Net MVC, please refer my article ASP.Net MVC: Call Controller Method from View using jQuery AJAX.
The URL for the jQuery AJAX call is set to the Controller’s action method i.e. /Home/AjaxMethod. The value of the TextBox is passed as parameter and the returned response is displayed using JavaScript Alert Message Box.
    Layout = null;
<!DOCTYPE html>
    <meta name="viewport" content="width=device-width"/>
    <input type="text" id="txtName"/>
    <input type="button" id="btnGet" value="Get Current Time"/>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        $(function () {
            $("#btnGet").click(function () {
                    type: "POST",
                    url: "/Home/AjaxMethod",
                    data: '{name: "' + $("#txtName").val() + '" }',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                    failure: function (response) {
                    error: function (response) {
ASP.Net MVC ContentResult Example: Return String Content from Controller to View in ASP.Net MVC