PartialView doesn't work (whole page refreshes instead)

Hi I'm new to MVC 4. I am having a partial view problem. I have searched for it and searched a lot and studied different tutorials but could not find a solution that can solve my problem. I created a PagedList to display the entries in the Index.cshtml page. Then I created a PartialIndex.cshtml page to display the records in a partial view. Here is the problem: when I click on any page number or navigate. The whole page refreshes and goes back ... partial view doesn't work. Not sure where I am doing wrong. I want to show a table inside a DIV in PartialIndex.cshtml

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

      

Index.cshtml:

<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />


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

@Html.Partial("PartialIndex")

      

+3


source to share


2 answers


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



+2


source


You better use



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

      

+3


source







All Articles