asp.net mvc partialview @ Ajax.ActionLink不起作用

时间:2022-09-21 03:19:54

I have a view page

我有一个视图页面

my view 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 brings me to a new page instead of replacing or appending the partial view to the div tag.

但是当我点击生成的链接时,它会将我带到一个新页面,而不是将部分视图替换或附加到div标签。

What's the problem?

有什么问题?

5 个解决方案

#1


10  

It could have been that you were missing the:

可能是你错过了:

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

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

在主视图中。这告诉主视图识别ajax助手。

#2


1  

I found the solution. The problem was due to the corrupted unobtrusive-ajax.min.js file.

我找到了解决方案。问题是由于损坏的unobtrusive-ajax.min.js文件造成的。

#3


0  

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

如果你有jQuery加载到你的页面,为什么不使用简单的jquery get / load方法来获取局部视图?

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

Javascript

使用Javascript

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

#4


0  

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

如果您正在使用ASP .NET MVC 4,请确保

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

is in the end of the body tag as well.

也在身体标签的末尾。

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

#5


0  

I've just been working on it for too long, thinking it did not work. Viewing the page source didn't show anything either.

我一直在研究它已经太久了,认为它不起作用。查看页面源也没有显示任何内容。

Eventually, I found out it actually did work when I saw the successful requests in the console of Firebug. It only was showing it off screen. In the HTML tab of Firebug I finally found the output, even though it does not show up in the page source.

最后,当我在Firebug的控制台中看到成功的请求时,我发现它确实起作用了。它只是在屏幕上显示出来。在Firebug的HTML选项卡中,我终于找到了输出,即使它没有显示在页面源中。

#1


10  

It could have been that you were missing the:

可能是你错过了:

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

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

在主视图中。这告诉主视图识别ajax助手。

#2


1  

I found the solution. The problem was due to the corrupted unobtrusive-ajax.min.js file.

我找到了解决方案。问题是由于损坏的unobtrusive-ajax.min.js文件造成的。

#3


0  

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

如果你有jQuery加载到你的页面,为什么不使用简单的jquery get / load方法来获取局部视图?

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

Javascript

使用Javascript

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

#4


0  

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

如果您正在使用ASP .NET MVC 4,请确保

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

is in the end of the body tag as well.

也在身体标签的末尾。

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

#5


0  

I've just been working on it for too long, thinking it did not work. Viewing the page source didn't show anything either.

我一直在研究它已经太久了,认为它不起作用。查看页面源也没有显示任何内容。

Eventually, I found out it actually did work when I saw the successful requests in the console of Firebug. It only was showing it off screen. In the HTML tab of Firebug I finally found the output, even though it does not show up in the page source.

最后,当我在Firebug的控制台中看到成功的请求时,我发现它确实起作用了。它只是在屏幕上显示出来。在Firebug的HTML选项卡中,我终于找到了输出,即使它没有显示在页面源中。