Last post Jul 25, 2010 08:57 PM by DamnRock
Jul 25, 2010 04:09 PM|DamnRock|LINK
Ok... I'm new to ASP.net MVC 2 so I'm writing a personal photo album website to get the feel for it. I'm going to describe what I've got to see if anyone has any opinions on a more appropriate way for this to be laid out.
The page is simple at this point. My controller sends the folder structure (all folders in Photos folder and photos within each folder (path to phoots)) plus the currently selected folder. The Index.aspx gets the folders and photos from Model and populates
a treeview with the folder structure and adds the photos for the currently selected folder to the .Controls collection of an ASP:Panel on the Content of the page. So, the treeview shows ALL folders, not just the level currently displayed.
If the user expands a level and clicks a folder, it calls /Photos/Drill?FolderName=whatever
/Photos/ <-- controller for Photos website
/Photos/Drill <-- action for drilling into thumbnail folder
All that does is call the Drill action of the Photos Controller which updates the Model.CurrentFolder property and passes it back to the Index.aspx to load the TreeView and photos again, only selecting the newly selected CurrentFolder.
I just realized in typing this... it may not be necessary to go back to the server when the user clicks a new folder in the tree view, as i already have the folders and photos loaded from the model. The only real action happening on the server in the Drill
action is that if the thubnails haven't been created yet, it will create them on the fly. I guess I could do that from the Index.aspx though, if necessary.
The way this page is setup, I can just ftp into my web server, create new photos folder and upload photos, and the page will figure it out and dynamically create thumbnails when necessary.
Any thoughts on this? I don't have any specific questions yet but I'm at the point where I want to be sure I'm going about this in a reasonable fashion, as there's no point in learning an old way of doing something if there's something better out there
I'll upload a screenshot tonight, as my webserver can't do .Net 4.0 yet so I can't upload anything for everyone to see.
Jul 25, 2010 06:05 PM|ignatandrei|LINK
The only thing that I do not like is that your application is modeling the folder structure. This is bad for security reasons. Please put files somewhere and retrieve images path at runtime with a http handler that you pass an id. In the httphandler you
can put security.(put the association id / path in a database - xml, sql server, you name it)
Otherwise, you have a pretty good app there ...
Jul 25, 2010 08:57 PM|DamnRock|LINK
Could you elaborate a bit on this? I haven't dealt with HttpHandler's yet so I read up a bit on it... looks to be a service I'll create that provides a synchronous response to my request?
Currently my Photos controller Index action looks like this:
public ActionResult Index()
_folder = PhotoHelpers.BrowseFolder(Server.MapPath("Content/Photos/"), "Content/Photos/");
// create a PhotosIndexViewModel, populate and send into View()
var photosViewModel = new PhotosIndexViewModel
Folder = _folder,
CurrentFolder = _folder
// create Thumbnails for images in Folder
The Folder class has a List<Folder> and List<Photo>. My initial request sends in the root of the Photos folder and calls the View. When they click on a folder, it goes into the Drill action, updates the CurrentFolder and calls the Index's View. I'm trying
to figure out at what point I would use an HttpHandler in this setup...
screen and set the current folder in the TreeView...
and THEN, I read somewhere that it's not recommended to use the <ASP:TreeView /> in ASP.Net MVC? something about post-backs, etc... but I don't think I'm far enough along to worry about that one yet... I'll probably end up learning jQuery and using the
jQuery TreeView plug-in to satisfy that requirement.