Home > DeveloperSection > Forums > How to return string result in mvc?
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    November-18-2014 2:13 AM

 ASP.NET MVC AJAX  ASP.NET MVC 
Ratings:


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



Mark Devid
Mark Devid

Total Post:101

Points:707
Posted on    November-18-2014 6:03 AM

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