IN MVC, HOW DO I RETURN A STRING RESULT?

Norman Reedus

Total Post:45

Points:315
Posted by  Norman Reedus
 866  View(s)
Ratings:
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. David Miller

    Post:30

    Points:210
    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");

Answer

NEWSLETTER

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