Short Version
You can't use an IActionResult in a Full Framework MVC or Web API as a result object. You'll have to map it to the appropriate type first. You should probably not use IActionResult in your class libraries, let the core project handle with return types
But ASP.NET Core doesn't require the .NET Core runtime, it can target the Full Framework as well. Perhaps you can use an ASP.NET Core project targeting the Full framework for your main project?
Explanation
ASP.NET Core is the "new" name for ASP.NET 5. It's a new framework that merges the MVC and Web API stacks and was built to run on both the older Full framework and what was then called DNXCore. Both names changed to ASP.NET Core 1.0 and Core .NET 1.0, leading to the confusion we have today.
Before ASP.NET Core, ASP.NET MVC and Web API were two different stacks, they used different controller base classes and returned different results. ASP.NET MVC used the abstract ActionResult class and Web API used the IHttpActionResult interface. Using an interface means it's a lot easier to test and mock the results, among other things. It also means that classes that implement it don't have to handle potentially unneeded properties and base methods.
In ASP.NET Core, the web framework, the entire stack was redesigned and now there's a single stack with a single base interface for results, IActionResult. Core's ActionResult is the default implementation but anyone can create a different implementation. RedirectResult for example doesn't need a Content property so it doesn't have one.
This interface is available to every .NET Standard 2.0 library as long as the appropriate package are added.
That doesn't mean it can be used as the actual return type in ASP.NET MVC 6 or Web API 2 projects though, because neither MVC's ActionResult nor Web API's IHttpActionResult implement it. One would have to write code to map from a concrete IActionResult instance to a concrete MVC ActionResult or Web API IHttpActionResult instance.
If your main project is ASP.NET Core though, you can use the interface whether it runs on the Full or Core framework.
.NET Standard
.NET Standard is a set of API specifications not a specific runtime. Each version specifies a set of classes and APIs that should be provided by a runtime that complies with that Standard version. When one creates a .NET Standard 2.0 library it means the code can use any of the classes and APIs defined in the 2.0 version.
Adding just the interface
IActionResult is not part of .NET Standard 2.0. It's provided by a package Microsoft.AspNetCore.Mvc.Abstractions.
The namespace is used the .NET Framework. If your project is targetting the .NET Framework, use System.Web.Mvc.System.Web.Mvc.ActionResult
Below list is all return type from System.Web.Mvc.ActionResult :
ViewResult : Represents HTML and markup.EmptyResult : Represents no result.RedirectResult : Represents a redirection to a new URL.JsonResult : Represents a JavaScript Object Notation result that can
be used in an AJAX application.JavaScriptResult : Represents a JavaScript script.ContentResult : Represents a plain text result.FileContentResult : Represents a downloadable file (with the binary
content).FilePathResult : Represents a downloadable file (with a path).FileStreamResult : Represents a downloadable file (with a file
stream).The namespace is used in .NET Core. If your project is targetting .NET Core, use Microsoft.AspNetCore.Mvc.Microsoft.AspNetCore.Mvc.ActionResult
ASP.NET Core offers the following options for web API controller action return types:
Specific typeIActionResultActionResult<T>List of common return types in Microsoft.AspNetCore.Mvc.ActionResult :
: Represents HTML and markup.ViewResult
: Represents content like plain text, XML, html.ContentResult
: Represents a JavaScript Object Notation result that can be used in an AJAX application.JsonResult
: Represents PartialView.PartialViewResult
: Represents a redirection to a new URL.RedirectResult
: Represents a redirection to specified action and controller.RedirectToActionResult
: Represents a redirection to a specified pageName (It is mostly used in Razor pages).RedirectToPageResult
: Represents a route to redirect from one controller to another controller in cases we have more than one route.RedirectToRouteResult
: Represents an HTTP status code.StatusCodeResult
: Represents a "ViewComponent".ViewComponentResult
: on execution invokes ChallengeResult.HttpContext.ChallengeAsync
: on execution invokes SignInResultHttpContext.SignInAsync
: on execution invokes SignOutResult.HttpContext.SignOutAsync
It is best for you to use async/await down the whole call stack which is possible with MVC. Mark your Action as async and then use the await keyword to wait for the results from the CsvReader method.
// changed signature to async and Task<ActionResult>
[HttpPost]
public async Task<ActionResult> Index(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var fileName = System.IO.Path.GetFileName(file.FileName);
var path = System.IO.Path.Combine(("C:\\Dev\\ProductionOrderWebApp\\Uploads"), fileName);
file.SaveAs(path);
// add await
await CSVReader(fileName);
}
return RedirectToAction("Index");
}
// did not check the code in the method but the signature should return type Task
public static async Task CSVReader(string fileName) {/*existing/unchanged code*/}
Really the best thing for you to do is to do a little reading on the async/await pattern so you are not just copy/pasting without understanding what is actually going on and why you are using it. It will also help you troubleshoot/debug possible issues later on.
Remove the attribute from the [HttpPost] action.display
If both actions are in the same controller, then just pass the action name:
return RedirectToAction("display", new { id = 1 });
Or if the actions are in different controllers, pass the action and controller names:
return RedirectToAction("display", "controllername", new { id = 1 });
Or if it is necessary to use , you can learn how to
[HttpPost] to a RedirectToAction Action.POST
You can just use the to return a plain string:ContentResult
public ActionResult Temp() {
return Content("Hi there!");
}
by default returns a ContentResult as its contentType. This is overloadable so you can also do:text/plain
return Content("<xml>This is poorly formatted xml.</xml>", "text/xml");