Working with ASP.Net Core is still a little new to me. I'm trying to follow a tutorial on PluralSight that details how Image Composition in .NET works.
That said, the code I'm trying to convert from ASP.Net MVC to ASP.Net Core is showing an error on Request
in my Index.cshtml
:
<img src="@Url.Action("ImageFromPath", new { path = Request.MapPath("~/img/1.jpg") })" />
The error is simply:
The name 'Request' does not exist in the current context.
My HomeController.cs
:
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public ActionResult ImageFromPath(string path)
{
var ms = new MemoryStream();
using (Bitmap bitmap = new Bitmap(path))
{
bitmap.Save(ms, ImageFormat.Jpeg);
}
ms.Position = 0;
return File(ms, "image/jpg");
}
}
In MVC, I can look up definition of Request
that goes all the way back to WebPageRenderingBase [from metadata]
, yet this does not exist in .NET Core, can anyone offer a way to get this to work?
EDIT - I later plan on using the backend ImageFromPath
method to return an image from an API call, not the file system.