views:

1257

answers:

2

Hi,

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

Do I still using ActionResult or just return a string?

+23  A: 

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");
swilliams
Ah thanks, never knew about this :).
Morph
That is nice! I also didn't know about this.
Chad
+7  A: 

You can also just return string if you know that's the only thing the method will ever return. For example:

public string MyActionName() {
  return "Hi there!";
}
Haacked