HOW TO RETURN STRING RESULT IN MVC?

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
 1305  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. Mark Devid

    Post:102

    Points:714
    Re: How to return string result in mvc?

    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!