Ajax PartialView不工作(改为整页刷新)

Ajax PartialView不工作(改为整页刷新),ajax,asp.net-mvc-4,pagedlist,ispostback,Ajax,Asp.net Mvc 4,Pagedlist,Ispostback,你好,我是MVC4新手。我对partialView有意见。。我用谷歌搜索了很多,研究了不同的教程,但找不到任何解决问题的方法。我创建了一个页面列表,在Index.cshtml页面上显示记录。然后我创建了PartialIndex.cshtml页面,以在部分视图中显示记录。 问题是:当我点击任何页码或导航时。。整个页面刷新并发回。。。局部视图不起作用。不知道我哪里做错了。 我想在PartialIndex.cshtml中显示DIV内的表 PartialIndex.cshtml: <div id=

你好,我是MVC4新手。我对partialView有意见。。我用谷歌搜索了很多,研究了不同的教程,但找不到任何解决问题的方法。我创建了一个页面列表,在Index.cshtml页面上显示记录。然后我创建了PartialIndex.cshtml页面,以在部分视图中显示记录。 问题是:当我点击任何页码或导航时。。整个页面刷新并发回。。。局部视图不起作用。不知道我哪里做错了。 我想在PartialIndex.cshtml中显示DIV内的表

PartialIndex.cshtml:

<div id="targetContainer"> //I want to show this DIV in partial view.
<table>
    <tr>
        <th>
            @Html.ActionLink("ID", "Index", new { sortOrder = ViewBag.customerID, currentFilter=ViewBag.CurrentFilter })
        </th>
        <th>
        </th>
        <th>
            @Html.DisplayName("First Name")
        </th>
        <th></th>
        <th>
            @Html.ActionLink("Last Name", "Index", new { sortOrder = ViewBag.lName, currentFilter=ViewBag.CurrentFilter })
        </th>
        <th></th>
        <th>
            @Html.DisplayName("Contact Num")
        </th>

        <th>
            @Html.DisplayName("Address")
        </th>

        <th>
            @Html.DisplayName("Email")
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.customerId)
        </td>
        <td>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.fName)
        </td>
        <td>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.lName)
        </td>
        <td>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.contactNum)
        </td>
        <td>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.address)
        </td>
        <td>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.email)
        </td>
        <td>
        @Html.ActionLink("Edit", "Edit", new { id=item.ID })
        @Html.ActionLink("Delete", "Delete", new { id=item.ID })
        </td>

    </tr>
}
</table>
</div>

<br />
       Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount

            @Html.PagedListPager(Model, page => Url.Action("Index", 
             new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(
                                       new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = "GET", UpdateTargetId = "targetContainer" }))
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />


@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@Html.Partial("PartialIndex")
//我想在局部视图中显示这个DIV。
@ActionLink(“ID”,“Index”,new{sortOrder=ViewBag.customerID,currentFilter=ViewBag.currentFilter})
@Html.DisplayName(“名字”)
@ActionLink(“姓氏”,“索引”,新的{sortOrder=ViewBag.lName,currentFilter=ViewBag.currentFilter})
@Html.DisplayName(“联系人编号”)
@Html.DisplayName(“地址”)
@Html.DisplayName(“电子邮件”)
@foreach(模型中的var项目){
@DisplayFor(modelItem=>item.customerId)
@DisplayFor(modelItem=>item.fName)
@DisplayFor(modelItem=>item.lName)
@DisplayFor(modelItem=>item.contactNum)
@DisplayFor(modelItem=>item.address)
@DisplayFor(modelItem=>item.email)
@ActionLink(“编辑”,“编辑”,新的{id=item.id})
@ActionLink(“删除”,“删除”,新的{id=item.id})
}

@Model.PageCount的@页(Model.PageCountUrl.Action(“索引”), 新建{page,sortOrder=ViewBag.CurrentSort,currentFilter=ViewBag.currentFilter}),PagedListRenderOptions.EnableUnobtrusiveAJAX替换( 新的AjaxOptions{InsertionMode=InsertionMode.Replace,HttpMethod=“GET”,UpdateTargetId=“targetContainer”})
Index.cshtml:

<div id="targetContainer"> //I want to show this DIV in partial view.
<table>
    <tr>
        <th>
            @Html.ActionLink("ID", "Index", new { sortOrder = ViewBag.customerID, currentFilter=ViewBag.CurrentFilter })
        </th>
        <th>
        </th>
        <th>
            @Html.DisplayName("First Name")
        </th>
        <th></th>
        <th>
            @Html.ActionLink("Last Name", "Index", new { sortOrder = ViewBag.lName, currentFilter=ViewBag.CurrentFilter })
        </th>
        <th></th>
        <th>
            @Html.DisplayName("Contact Num")
        </th>

        <th>
            @Html.DisplayName("Address")
        </th>

        <th>
            @Html.DisplayName("Email")
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.customerId)
        </td>
        <td>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.fName)
        </td>
        <td>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.lName)
        </td>
        <td>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.contactNum)
        </td>
        <td>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.address)
        </td>
        <td>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.email)
        </td>
        <td>
        @Html.ActionLink("Edit", "Edit", new { id=item.ID })
        @Html.ActionLink("Delete", "Delete", new { id=item.ID })
        </td>

    </tr>
}
</table>
</div>

<br />
       Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount

            @Html.PagedListPager(Model, page => Url.Action("Index", 
             new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(
                                       new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = "GET", UpdateTargetId = "targetContainer" }))
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />


@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@Html.Partial("PartialIndex")

@{
ViewBag.Title=“Index”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
@Html.Partial(“PartialIndex”)
您最好使用

Html.RenderPartial("~/Views/Shared/_Yourpartial.cshtml")

Html.RenderPartial(“~/Views/Shared/PartialIndex.cshtml”)

PartialIndex.cshtml的路径正确。我猜您指向的是查看页面的路径。顺便说一句,我尝试了你建议的解决方案,但没有成功。@MuzamilRafique:我们可以在你得到页面时看到呈现的html吗?我不知道你的PagedListPager是如何工作的,所以用html它可能会帮助我看到它。页面呈现像html一样简单,但使用AJAX的部分视图不起作用。当我点击任何页码时,整个页面都会刷新。请给出html。如果我看不到Ajax和页码,我将无法帮助您!