views:

27

answers:

1

How can you create a route that accept an undefined number of strings? The folder browser should be able to browse the specified folder and all the sub folders. Using JQuery to get the folders back from the server. The problem is how to build the JQuery?

$.ajax({
           type: "POST",
           url: "http://localhost:30218/Data/Folder1/Folder2/etc",
           dataType: "json",
           success: function (data) { }
       });

I mean, how can you create a MVC 2 url that could be like 10 subfolders deep? I don't want to define a static number of maximum folders that it can contain. How can you create the url and what routing should you use? Querystrings for subfolders?

+2  A: 

You can use the catchall on the last route segment, which is the asterisk character, like so:

"Files/{action}/{*path}"

That would cause everything at the end to be lumped together in the path parameter.

Andrew Barber
You could also, if you're feeling adventurous, make your actions take a DirectoryInfo type then define a model binder for it that would take the path and map it to the physical directory for you.
Chao
+1 I like adventure!
Andrew Barber