Note that there are some explanatory texts on larger screens.

plurals
  1. POGrid not updating after ajaxcall
    primarykey
    data
    text
    <p>I'm creating my own filter. The filter has a dropdownlist, when this dropdownlist changes jquery will make an ajaxcall to the corresponding HTTPPOST - controller action. In this action I filter the list and pass it through to my view.</p> <p>Once the list has reached my view, the webgrid is not updating. Here is some code with some debug information to show what's happening.</p> <h2>Controller</h2> <p>normal action </p> <pre><code> public ActionResult Projects() { IEnumerable&lt;Project&gt; projects = Adapter.ProjectRepository.Get(); int test = projects.Count(); List&lt;ProjectsDisplayViewmodel&gt; projectsView = new List&lt;ProjectsDisplayViewmodel&gt;(); string strCats = ""; foreach (Project prj in projects) { strCats = ""; Mapper.CreateMap&lt;Project, ProjectsDisplayViewmodel&gt;(); ProjectsDisplayViewmodel newProject = Mapper.Map&lt;Project, ProjectsDisplayViewmodel&gt;(prj); foreach (Category cat in prj.Categories) { strCats += cat.CategoryName + ", "; } newProject.strCategories = strCats; projectsView.Add(newProject); } ViewBag.Categories = new SelectList(Adapter.CategoryRepository.Get(), "CategoryID", "CategoryName"); /*projectsview contains 4 projects now*/ return View(projectsView); } </code></pre> <p>httppost action</p> <pre><code>[HttpPost] public ActionResult Projects(string catID, string strSearch) { IEnumerable&lt;Project&gt; projects = Adapter.ProjectRepository .Get() .Where(x =&gt; x.Categories.Any( c =&gt; c.CategoryID == Convert.ToInt16(19)) ); int test = projects.Count(); List&lt;ProjectsDisplayViewmodel&gt; projectsView = new List&lt;ProjectsDisplayViewmodel&gt;(); string strCats = ""; foreach (Project prj in projects) { strCats = ""; Mapper.CreateMap&lt;Project, ProjectsDisplayViewmodel&gt;(); ProjectsDisplayViewmodel newProject = Mapper.Map&lt;Project, ProjectsDisplayViewmodel&gt;(prj); foreach (Category cat in prj.Categories) { strCats += cat.CategoryName + ", "; } newProject.strCategories = strCats; projectsView.Add(newProject); } ViewBag.Categories = new SelectList(Adapter.CategoryRepository.Get(), "CategoryID", "CategoryName"); /*projectsview contains 1 project now AND WILL DISPLAY 4*/ return View(projectsView); } </code></pre> <h2>project.cshtml</h2> <pre><code>@model IEnumerable&lt;Freelauncher.Models.ProjectsDisplayViewmodel&gt; @{ ViewBag.Title = "Projects"; } @{ var grid = new WebGrid(Model, canPage: true, rowsPerPage: 25, selectionFieldName: "selectedRow",ajaxUpdateContainerId: "gridContent"); grid.Pager(WebGridPagerModes.NextPrevious); } &lt;h2&gt;Alle projecten&lt;/h2&gt; @Html.DropDownList("Categories", (SelectList) ViewBag.Categories) &lt;div id="gridContent"&gt; @grid.GetHtml( columns: grid.Columns( grid.Column("ProjectTitle", "Titel"), grid.Column("ProjectDeadlineDate", "project deadline"), grid.Column("ProjectEndRegisterDate", "Registreer deadline"), grid.Column("ProjectBudget", "Prijs"), grid.Column("ProjectIsFixedPrice", "Vaste prijs"), grid.Column("strCategories","Categorieën"), grid.Column("ProjectID", "meer info", format: (item) =&gt; Html.ActionLink("info", "project", new { Id = item.ProjectID} )) //grid.Column("ProjectID", "meer info", format: Html.ActionLink("info", "project", new { Id = } )) &lt;/div&gt; </code></pre> <p>What am I missing that the project list in my view is not updated, the correct data is passed to the view....</p> <h2>edit</h2> <p>The ajax call</p> <pre><code>$("#Categories").change(function () { var param = $(this).val(); $.ajax({ type: "POST", url: "/Project/Projects", data: { catID: $(this).val(), strSearch: 'test' }, dataType: "json", success: function (response) { console.log("succes"); }, error: function (xhr, ajaxOptions, thrownError) {console.log("error"); } }); }); </code></pre> <p>I just noticed that nothing is printed in my console.log.... Not the success neither the error function.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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