0

This action method renders a partial view, which is embedded in another view.

public ViewResult List(int page = 1) { int totalComments; ProductListViewModel prodViewModel = new ProductListViewModel { CommentsPaginated = repository.CommentsPaginated(page, PageSize, out totalComments), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = totalComments } }; ViewBag.Page = page; return View(prodViewModel); } 

The List view:

@model ProductWindow.WebUI.Models.ProductListViewModel @{ ViewBag.Title = "List"; } <br /> <h2>List Products</h2> @foreach (var m in Model.CommentsPaginated) { <div class="item"> @m.NR, @m.TXT, @m.ENABLED </div> } 

The enclosing Index view:

@model string @{ ViewBag.Title = "Index"; AjaxOptions ajaxOpts = new AjaxOptions { UpdateTargetId = "commentsData" }; } <h2>Index</h2> Static part of the page. <h2>Index page</h2> @using (Ajax.BeginForm("List", ajaxOpts)) { <div id="commentsData"> @Html.Action("List", new {page = Model}); </div> <input type="hidden" name="page" value="3" /> <input type="submit" value="Submit" /> <!-- I use Ajax.ActionLink here, but it acts the same --> } 

QUESTION:

Whenever I click on Submit, List action method gets fired more and more times (1, 2, 4, 8, 16...). Any idea why?

1 Answer 1

2

Solved it. Changed the List return value to PartialViewResult, and called PartialView() at the end of the same function.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.