NMathur NMathur - 20 days ago 7
ASP.NET (C#) Question

unable to set updated partial view data to div. ASP.NET MVC

I am showing a list (partial view) on my view and the view has a "Add" button. Clicking on "Add" I go to different view and the action there redirect me back to the list view ..

return RedirectToAction("List", "Home");


The issue is as following : --


  • Suppose I have 4 items to the list .. Item1, Item2, Item3 and Item4

  • When I go to the list page from menu .. all 4 items are there.

  • Then I click to add and add the Item5 there This actiob redirect me
    back to list page ... but I can see only 4 items here ..

  • then I manually reload the page by pressing enter on browser's
    address bar ..

  • Now I can see 5 items .. .. again .. Add .. no new item displaying
    in the list. .. :(



To show the list I am using partial view ..

Tried following: both are giving same result :(

Method 1.

<div id="showListHere">
@{ Html.RenderAction("ShowList", "Home"); }
</div>


Method 2.

$(function(){

// Load list
$(document).ready(function(){
$(function(){
$.ajax({
url :'@Url.Action("ShowList", "Home")',
success : function(data){
$('#showListHere').html(data);
}
});
});

});
});


Controller code :

[HttpGet]
public ActionResult ShowList()
{
var result = MyFunctions.GetListResult();
return PartialView("_ListPartialView", result);
}


Please share suggestions ..

Answer

I faced same issue once .. the reason was that my add process was taking time .. before completing the add process I was showing data to my view. My action was aync Task. ..

Solution : -- Show progress bar until the action is completely done and then show the result.

Hope this can help someone.