@Ajax.ActionLink("please click ...">

Asp.net mvc partialview @ Ajax.ActionLink not working

I have a watch page

my browse page

<div id="beReplaced"> @Ajax.ActionLink("please click on me to bring the partial view", "PatrialViewToBeCalled", new AjaxOptions() {UpdateTargetId = "beReplaced", InsertionMode = InsertionMode.InsertAfter, HttpMethod="Get", LoadingElementId = "prgress" }) </div> 

I have a controller

 public PartialViewResult PatrialViewToBeCalled() { var customer = db.Customers.First(); return PartialView("PartialViewThatMustBeShow",customer); } 

but when I click on the generated link, it takes me to a new page instead of replacing or adding a partial view to the div tag.

What is the problem?

+8
ajax asp.net-mvc asp.net-mvc-partialview
source share
5 answers

I have found a solution. The problem arose due to a damaged unobtrusive ajax.min.js. file

+1
source share

You may have been absent:

 <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script> 

In the main window. This tells the main view to recognize the ajax helper.

+10
source share

If you have jQuery loaded into your page, why not use the simple get / load jquery method to get a partial view?

 <div id="beReplaced"> <a href="#" id="lnk1">please click on me to bring the partial view</a> </div> 

Javascript

 $("#lnk1").click(function(){ $.get('/controller/PatrialViewToBeCalled', function(data) { $('#beReplaced').html(data); }); }); 
0
source share

If you are working with ASP.NET MVC 4, make sure that

  @Scripts.Render("~/bundles/jquery") 

also located at the end of the body tag.

  @Scripts.Render("~/bundles/jquery") @RenderSection("scripts", required: false) </body> </html> 
0
source share

I worked on this for too long, thinking it didn't work. Viewing the source of the page also showed nothing.

In the end, I found out that it really worked when I saw successful requests in the Firebug console. It just showed it off the screen. On the Firebug HTML tab, I finally found a way out, although it does not appear in the page source.

0
source share

All Articles