ASP.NET Core提供了多种返回结果的方法。以下是几个常见的示例:
public IActionResult GetString()
{
return Content("Hello World");
}
public IActionResult GetJson()
{
var data = new { Name = "John", Age = 30 };
return Json(data);
}
public IActionResult GetView()
{
return View();
}
public IActionResult GetFile()
{
var filePath = "path/to/file.txt";
return PhysicalFile(filePath, "text/plain");
}
public IActionResult GetRedirect()
{
return RedirectToAction("ActionName", "ControllerName");
}
public IActionResult GetError()
{
return NotFound();
}
这些只是ASP.NET Core中返回结果的一些示例,你可以根据具体需求选择适合的方法。