使用ajax actionlink加载局部视图

问题描述 投票:0回答:1

我一直在尝试加载部分视图,但是当单击链接时,它会插入整个网站,而不仅仅是部分视图。我在做什么错?

在我的模板中,我有:

@Ajax.ActionLink("View list",
    "List",
    "SwitchView",
    new AjaxOptions()
         {
        UpdateTargetId = "testajax",
        InsertionMode = InsertionMode.Replace,
        HttpMethod = "GET"
    })

<div id="testajax"></div>

@section Scripts {
   <script src="@Url.Content("~/Assets/framework/js/unobtrusive-ajax/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
}

我的控制器:

public class SwitchViewController : Controller
    {
        public PartialViewResult List()
        {
            return PartialView("~/Views/Partials/kund.unikum.se/_ListView");
        }
    }

由于缺少这些设置,我还在web.config中添加了这些设置:

<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

而且,当查看生成的html链接时,它缺少“ href”值?

<a data-ajax="true" data-ajax-method="GET" data-ajax-mode="replace" data-ajax-update="#testajax" href="">View list</a>

Screenshot of the loaded resources and the view

ajax asp.net-mvc partial-views actionlink
1个回答
0
投票

您是否已在局部视图中设置Layout=null?如果没有,则进行设置并检查。让我知道您是否仍然面临这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.