FYI Response.Write
is removed from MVC
.
There are two Solutions for .Net Core MVC
is by using Content Result
or by writing your custom ActionResult
by overriding ExecuteResult
method as below.
1. Using Content Result
public IActionResult Index()
{
return Content("Hello World !");
}
or even Just return string
method
public string Index()
{
return "Hello World !";
}
2. Custom Action Result:
public class ResponseWriteActionResult : ActionResult
{
public override void ExecuteResult(ActionContext context)
{
var str = Encoding.ASCII.GetBytes("Hello World !");
context.HttpContext.Response.Body.Write(str, 0, str.Length);
}
}
Usage:
public IActionResult Index()
{
return new ResponseWriteActionResult();
}
References:
1.
2.
3.