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

发布于 2024-12-25 10:36:03 字数 766 浏览 4 评论 0原文

我有一个视图页面

我的视图页面

<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>

有一个控制器,

public PartialViewResult PatrialViewToBeCalled()
{
    var customer = db.Customers.First();

    return PartialView("PartialViewThatMustBeShow",customer);
}   

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

有什么问题吗?

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.

What's the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

想念有你 2025-01-01 10:36:04

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

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

也位于 body 标记的末尾。

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

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

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

is in the end of the body tag as well.

      @Scripts.Render("~/bundles/jquery")
        @RenderSection("scripts", required: false)
    </body>
</html> 
猥︴琐丶欲为 2025-01-01 10:36:04

我已经为此工作了太长时间,认为它不起作用。查看页面源也没有显示任何内容。

最终,当我在 Firebug 的控制台中看到成功的请求时,我发现它确实有效。它只是在屏幕外展示它。在 Firebug 的 HTML 选项卡中,我终于找到了输出,尽管它没有显示在页面源代码中。

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.

疾风者 2025-01-01 10:36:03

可能是您错过了:

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

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

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.

千年*琉璃梦 2025-01-01 10:36:03

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

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

心凉 2025-01-01 10:36:03

如果您已将 jQuery 加载到页面中,为什么不使用简单的 jquery get/load 方法来获取部分视图呢?

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

If you have jQuery loaded into your page, why not use the simple jquery get / load method to get the 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);
      });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文