I am creating one MVC3 Razor application.I used file upload.I need to save and display image.Uploaded image is not shown in Visual Studio’s folder but when i open same folder from windows then image is shown. After then the upload is working.
My controller:
public ActionResult Save(HttpPostedFileBase attachments)
{
var fileName = Path.GetFileName(attachments.FileName);
var physicalPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
attachments.SaveAs(physicalPath);
string fnn = fileName;
ViewBag.fnn = fnn;
return Content("");
}
As I said in the comment, the items that are shown in folders inside Visual Studio are items that are used for your solution.
When your application is deployed online and running it won’t have anything to do with VS. VS won’t even be running.
It looks like you are uploading the file correctly, and it is behaving exactly like it should be. If you want to add the file you uploaded to VS just right click on the folder and select
AddthenExisting Itemand select the file. Granted you didn’t need to upload it to get it into your solution, you could have just added it to the folder to start with.If you would like to display the image in your site, you would do something like this:
Keep in mind that
ViewBag.fnnmust have the path to the file, not just the file name. Andalt=is just a description of the image.