Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display string from action result

there is a action: /Home/GetName, and return a string "Mike", the controller and action like:

public class HomeController : Controller
{
    public string GetName()
    {
        return "Mike";
    }
}

how can I display this action result in view? (without ajax is better)

like image 302
Mike.Jia Avatar asked Jan 19 '16 07:01

Mike.Jia


1 Answers

You can use the ContentResult to return string like

public ActionResult GetName() {
    return Content("Mike");
}

Note that by default a type of text/plain is returned by ContentResult.

like image 75
Rahul Tripathi Avatar answered Oct 14 '22 12:10

Rahul Tripathi