I uploading files in asp.net core mvc i create folder for images in wwwroot with the name of photo and write a program in controller in which gives error of null _IWebHostEnvironment.WebRootPath can anybody help me.
namespace eHouse.Controllers {
public class AddPropertyRentController1 : Controller
{
Rentdb DB =new Rentdb();
IWebHostEnvironment _IWebHostEnvironment;
public IActionResult aprent()
{
return View();
}
[HttpPost]
public IActionResult aprent([Bind] RentModel ar)
{
if (ar.imge1 != null)
{
string folder = "image/";
folder += ar.imge1.FileName + Guid.NewGuid().ToString();
ar.pic1 = folder;
string serverFolder = Path.Combine(_IWebHostEnvironment.WebRootPath, folder);
ar.imge1.CopyToAsync(new FileStream(serverFolder, FileMode.Create));
}