Reputation: 2674
I want to create a page where I can upload pictures and at the same time bring them to the page.
for example: I have a picture controller which has Index, addpictures in View.
Could anyone please help me?
I am a beginner, so it would be great if you'd write as simple as possible. Thanks in advance.
Upvotes: 2
Views: 3141
Reputation: 1038710
You may take a look at the following blog post for a tutorial about uploading files in ASP.NET MVC.
The Path class is defined in the System.IO namespace so you will have to bring that into scope.
If you want to be able to show the uploaded file you will have to store it in some other folder than the App_Data. Files are not directly accessible by clients from this folder. You could for example use the Content folder instead. Once you get the file appear in this folder on the server you could reference it from the view using the <img>
tag: <img src="@Url.Content("~/content/someimage.jpg")" /
> where you could pass the name of the file to the view from the upload action.
Upvotes: 5