In MVC, how do I return a string result?

Total Post:45


 1371  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?

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

      Modified On Apr-08-2018 11:51:44 PM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.