In MVC, how do I return a string result?

user67033 picture user67033 · Feb 16, 2009 · Viewed 300.6k times · Source

In my AJAX call, I want to return a string value back to the calling page.

Should I use ActionResult or just return a string?

Answer

swilliams picture swilliams · Feb 16, 2009

You can just use the ContentResult to return a plain string:

public ActionResult Temp() {
    return Content("Hi there!");
}

ContentResult by default returns a text/plain as its contentType. This is overloadable so you can also do:

return Content("<xml>This is poorly formatted xml.</xml>", "text/xml");