Partial view of MVC Ajax update

I want to update a partial view every time an ActionLink is clicked. I pass the same model to a partial view as the main view. The problem is that the partial view is not updated. Not sure I'm on the right track.

View :

@model MyPoll.Models.Poll @Ajax.ActionLink("For", "AddPositive", new RouteValueDictionary { {"id", Model.Id }},new AjaxOptions() { UpdateTargetId = "countsDiv" }) <div id="countsDiv"> @Html.Partial("Counts", Model) </div> 

Partial

 @model MyPoll.Models.Poll Positive count : @Model.PositiveCount Negative count : @Model.NegativeCount 

Controller action :

 public ActionResult AddPositive(int id) { Poll poll = db.Polls.Find(id); poll.PositiveCount++; db.SaveChanges(); return View(poll); } 

Scripts also link:

  <script src="/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script> <script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script> <script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script> 
+6
source share
2 answers

Fixed

In action:

 public **PartialViewResult** AddPositive(int id) { Poll poll = db.Polls.Find(id); poll.PositiveCount++; db.SaveChanges(); return **PartialView**("Counts", poll); } 
+6
source

Probably because you are loading the latest jquery. Other js depend on jquery.

0
source

Source: https://habr.com/ru/post/904617/


All Articles