I want to update the partial view every time the ActionLink is clicked. I'm passing the same model to the partial view as the main view. The problem is that partial view is not getting updated. Not sure if I'm on 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);
}
The scripts are referenced as well:
<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>
Fixed:
In action :
public **PartialViewResult** AddPositive(int id)
{
Poll poll = db.Polls.Find(id);
poll.PositiveCount++;
db.SaveChanges();
return **PartialView**("Counts", poll);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With