0

I am trying to load a partial view inside of the main view, and a similar question was posted here - ' How can i load Partial view inside the view ' explaining how to use ajax actionlinks, but I still can't seem to get this working without the partial view displaying on a brand new page.

Here is the basis of my code that is in the main view,

        <td>

            @Ajax.ActionLink(
                item.FirstName,
                "DisplayApplication",
                new { ID = item.PersonID },
                new AjaxOptions { UpdateTargetId = "ApplicationByPerson" }
            )
        </td>
...

<div id="ApplicationByPerson"></div>

Then later down the page I have a Div called "ApplicationByPerson" I want my partial view displayed in.

In my controller I then have the code,

    public ActionResult DisplayApplication(int ID)
    {
        var tmp = db.Persons.Where(x => x.PersonID == ID).Include(y => y.Apps).FirstOrDefault();

        return View(tmp.Apps);
    }

The right information is being returned to the view, but it is displaying by itself as a new view. I'm sure it is something simple I am doing wrong.

Community
  • 1
  • 1
user3407039
  • 1,285
  • 5
  • 25
  • 51
  • Probably because you are missing the required jquery files `jquery-unobtrusive-ajax-js` –  Feb 05 '15 at 10:07
  • ' itself as a new view ' means?? – malkam Feb 05 '15 at 10:07
  • At the bottom of my page I have – user3407039 Feb 05 '15 at 10:09
  • Are you referring layout in partial view? – malkam Feb 05 '15 at 10:14
  • Check in the browser that the file is actually being loaded, at that javascript has not been disabled. –  Feb 05 '15 at 10:22
  • No, it is in the layout for the main file with the header and footer that are used for every page, is that correct? JavaScript is enabled and the file is being fully loaded. – user3407039 Feb 05 '15 at 10:40
  • Possibly you have the scripts out of order, or are including them multiple times –  Feb 06 '15 at 02:27
  • I only mention it the once right before the close of my body tag. And the only things also there are the scripts.render() for jquery and bootstrap (I have tried p;lacing these before and after - no difference). I think I did check correctly, but how would you check in the browser to make sure the file is being loaded correctly? – user3407039 Feb 06 '15 at 09:12
  • OK I finally got it working. You were right about the ordering. The ajax script needed to be loaded after JQuery. – user3407039 Feb 06 '15 at 11:49

0 Answers0