I'm very new to ASP.NET MVC, but even more than that, I'm very new to web development in general. What I want to do is simple. I have a folder in my MVC project called /Content/Images where I have some images. I'd like for my controller to grab all the images in this folder, and send them to the view. The view will then render these images in a div, and add a Javascript function to them on their click event. So, my question basically is, how do you browse the files on the server in ASP.NET MVC.
If I'm going about this the wrong way all together, please let me know as well. The main goal here is to have a little scrollable area on part of the page with all the pictures in a certain folder, and all the images should have an onclick that calls a javascript function passing in the name of the image. Hope that makes sense!
-
You can use DirectoryInfo to get a list of all the files in the the images directory
DirectoryInfo folder = new DirectoryInfo(Server.MapPath("/content/images")); foreach(FileInfo file in folder.Files) // find all your files here
BFree : Server.MapPath is exactly what I needed. Thanks! I do think you meant DirectoryInfo though, I'll edit your post if you don't mind. One last thing, am I going about this whole idea the right way?Jason : Yes, you are. There is nothing MVC specific about what you're trying to do, you just want to build a list of server side files and expose it via a view/page.BFree : Perfect, thanks man.
0 comments:
Post a Comment