Put the code on first.
[HttpPost] Publiciactionresult importteaching (iformfile file) {stringRoot =@"temp/teachingfile/"; stringPhypayh =EVN. MapPath (root); if(File! =NULL) { varParsedcontentdisposition =contentdispositionheadervalue.parse (file. Contentdisposition); varOriginalname = ParsedContentDisposition.FileName.Replace ("\"",""); File. SaveAs (Phypayh+originalname); } Else{modelstate.addmodelerror ("","No file selected"); returnView (); } returnRedirecttoaction ("Index"); }
You must first get the ihostingenvironment inside the service.
The following code
[fromservices] publicsetget;}
Note: this
Ihostingenvironment is automatically registered to the service when it is started. can be directly obtained
Special attention:
Now the virtual path is written in a different way before the MVC5 is similar:string root = "~/livefile/";
Now is:string root = "livefile/";
I have tried many times before in accordance with MVC5 's wording.
ASP. NET 5 upload file stored via virtual path