Member_4438002
asked on
Ajax and MVC
Hi, I am a beginner to Ajax and MVC, and am trying to figure out how to get a particular thing to work
Basically, I have a method that gets all directories/subdirectories from a given root directory, and what I want to do is clicking on a directory to have it populate a span/div directly below it with all the files within that directory
I'll show you what I've got right now, and hopefully you'll be able to tell me what I'm missing/doing wrong. Thanks a lot for your time
Controller:
View:
Partial View GetFiles:
Now I think I'm just missing some javascript, or am mis-using the Ajax Action link, as currently clicking on the link will just open up the partial view as a new page, but not quite sure how to pull it all together
Basically, I have a method that gets all directories/subdirectories
I'll show you what I've got right now, and hopefully you'll be able to tell me what I'm missing/doing wrong. Thanks a lot for your time
Controller:
public PartialViewResult GetFiles(string path)
{
ImageFileModel[] files = OriginationViewerModelBuilder.GetImageFiles(path);
return PartialView(files);
}
View:
@helper ShowDirectoryTree(ImageDirectoryModel imageDirectory)
{
<ul>
<li>
<b>@Ajax.ActionLink(imageDirectory.Path,"GetFiles",new {path = imageDirectory.Path},new AjaxOptions{UpdateTargetId=imageDirectory.FileSpanID})</b>
<span id="@imageDirectory.FileSpanID"></span>
</li>
@if (imageDirectory.ImageSubDirectories.Any())
{
foreach (var sub in imageDirectory.ImageSubDirectories)
{
@ShowDirectoryTree(sub);
}
}
</ul>
}
@Model.Title
Image Folder: @Model.Configuration.Options.OriginalImagesFolder
<br />
@foreach (var directory in Model.ImageDirectories)
{
@ShowDirectoryTree(directory);
}
Partial View GetFiles:
@model IEnumerable<ImageFileModel>
<ul>
@foreach (var file in Model.ToArray())
{
<li>@file.Filename</li>
}
</ul>
Now I think I'm just missing some javascript, or am mis-using the Ajax Action link, as currently clicking on the link will just open up the partial view as a new page, but not quite sure how to pull it all together
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER