Link to home
Start Free TrialLog in
Avatar of Member_4438002
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:
public PartialViewResult GetFiles(string path)
        {
            ImageFileModel[] files = OriginationViewerModelBuilder.GetImageFiles(path);
            return PartialView(files);
        }

Open in new window


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);
}

Open in new window


Partial View GetFiles:
@model IEnumerable<ImageFileModel>

<ul>
    @foreach (var file in Model.ToArray())
    {
        <li>@file.Filename</li>
    }
</ul>

Open in new window


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
Avatar of Steven Kribbe
Steven Kribbe
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Member_4438002
Member_4438002

ASKER

I see, thanks a lot for the response.  I forgot about this question as I had to go non-ajax in the end but your response makes sense