This might be a simple problem that I have been over thinking, but I can’t think of what needs to be done.
<div class="commentsMain">
... Contents loaded with ajax ...
</div>
<script type="text/javascript">
$(document).ready(function() {
var maxPage = @Model.NumberOfPages;
var nextPage = @Model.CurrentPage + 1;
// Loads new comments and adds them to the comments main div
$("#loadNextComments").live("click",function() {
if (nextPage <= maxPage) {
$("#loadNextCommentsDiv").remove();
loadNewComments('@Url.Action("Comments", "Comments")', nextPage, @Model.CommentItemId, @Model.CommentItemType );
nextPage++;
}
});
// This function submits the comment and then the nextPage variable
// is supposed to be set back to @Model.CurrentPage + 1
$('#commentSubmitButton').on("click",submitComment(@Model.CommentItemId, @Model.CommentItemType, addAction, nextPage));
});
</script>
After the commentSubmitButton click I need the nextPage variable to be re-assigned with the proper value from the model. How can I achieve this? I could do this in the ajax “success” function, but the function is in an external file and I don’t know if I can somehow re-assign the variable from there.
Thanks for helping.
remove the
var-keyword beforenextPageandmaxPageto make the variables global