In MVC, how do I return a string result?

Total Post:45

 1151  View(s)
Rate this:

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?

  1. Post:30

    Re: In MVC, how do I return a string result?

    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");

      Modified On Apr-08-2018 11:51:44 PM



Enter your email address here always to be updated. We promise not to spam!