Home > DeveloperSection > Forums > In MVC, how do I return a string result?
Norman Reedus
Norman Reedus

Total Post:45

Points:315
Posted on    January-22-2015 10:31 PM

 ASP.Net C#  AJAX  ASP.NET MVC 
Ratings:


 1 Reply(s)
 575  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?



David Miller

Total Post:30

Points:210
Posted on    January-22-2015 11:03 PM

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


Don't want to miss updates? Please click the below button!

Follow MindStick