In this article I will explain with an example, how to use ContentResult in .Net Core.
ContentResult return type is used for returning Content i.e. String, XML string, etc. from Controller to View in ASP.Net Core MVC.
Controller
The Controller consists of the following Action method.
Action method for handling GET operation
Inside this Action method, the string message is sent to the Client using Content function.
Note: The Content function sends the data to the Response similar to Response.Write function.
public class HomeController : Controller
{
public ContentResult Index(ControllerContext context)
{
return Content("Hello MVC Core!");
}
}
Screenshot
Downloads