partial view not showing

637 views Asked by At

i have a partial view named "_PartialPage1" under "X" controller. here's the content of my partial view:

<div>Hello</div>

my X controller contains this:

    public ActionResult _PartialPage1()
    {
        return View();
    }

in my home index, i have this:

 <div style="float:left"> @Ajax.ActionLink("Call X", "_PartialPage1", "X", new AjaxOptions() { UpdateTargetId = "divToUpdate" }) </div>
 <div style="float:left"> @Ajax.ActionLink("Call Y", "_PartialPage2", "Y",new  AjaxOptions(){ UpdateTargetId = "divToUpdate" }) </div>
 <div style="float:left"> @Ajax.ActionLink("Call Z", "_PartialPage3", "Z",new  AjaxOptions(){ UpdateTargetId = "divToUpdate" }) </div>

 <div id="divToUpdate"></div>

when i click Call X, nothing is being shown.. i am trying to learn ajax partial page update.... hope you can help me... thanks :)

2

There are 2 answers

0
lopezbertoni On BEST ANSWER

If you want to render a partial view you should use:

@Html.Partial("PartialViewName"); 

Where you have a partial view named "PartialViewName" with the div tag hello

0
DMulligan On

If you have

  • A controller named XController containing an action named _PartialPage1
  • References to both the jquery and jquery.unobtrusive-ajax javascript libraries on the page you're using
  • A view in the correct folder named "_PartialPage1"
  • A div with the id divToUpdate

Then your code you provided should work. I would check that all of these conditions are met. I recommend using firebug to verify that your ajax call is working. Returning a PartialView instead of a View is more appropriate, but you should see results within your div either way.