Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax.ActionLink duplicating and inserting the entire view into a <div> inside that view
    primarykey
    data
    text
    <p>I am new to MVC and working on an e-commerce application for my aunt's business. I have a Product List page with a partial view to display a menu to search by category. It all worked just fine with Html.ActionLink helpers, but when I switched to AJAX, it updates the products but inserts the entire List view into the div that I want updated(header and everything included). I'm assuming it has something to do with the UpdateTargetId I defined, or perhaps the layout(I'm no css whiz). So here goes:</p> <p>ProductController:</p> <pre><code>public ViewResult List(string category, int page = 1) { JProductListViewModel model = new JProductListViewModel { JProducts = repository.JProducts .Where(p =&gt; category == null || p.Category == category) .OrderBy(p =&gt; p.ProductID).Skip((page - 1) * PageSize).Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = category == null ? repository.JProducts.Count() : repository.JProducts.Where(x =&gt; x.Category == category).Count() }, CurrentCategory = category }; return View(model); } </code></pre> <p>Menu Partial:</p> <pre><code>@foreach (var link in Model) { &lt;div class="catmenuitem"&gt; @if (link != null) { @Ajax.RouteLink(link, "", new { controller = "Product", action = "List", category = link, page = 1 }, new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "List", LoadingElementId = "loading", LoadingElementDuration = 1000 }, new { @class = link == ViewBag.SelectedCategory ? "selected" : null }) } &lt;/div&gt; } </code></pre> <p>List View:</p> <pre><code>&lt;div id="List"&gt; @foreach (var p in Model.JProducts) { Html.RenderPartial("ProductSummary", p); } &lt;/div&gt; </code></pre> <p>The result I am getting is the entire List.cshtml view being duplicated and inserted into the "List" div. I have a feeling it will be some sort of silly mistake, but I can't seem to find it.</p> <p>Thanks, Kwinsor5</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload