How to return string result in mvc?

Total Post:183

Points:1285

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

      Modified On Apr-06-2018 06:50:39 AM

Answer

Please check, If you want to make this post sponsored

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