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>
source share