Question

How do you pass values from a model to a javascript paging script in MVC? I have a paging model and need to pass values to the following javascript in the view template:

  <script type='text/javascript'>
    var options = {
        currentPage: 2,
        totalPages: 4,
        numberOfPages: 5,
        onPageChanged: function(e,oldPage,newPage){

        },
        pageUrl: function(type, page, current) {

I need to pass values in my model to replace the hard coded values in the above javascript.

Was it helpful?

Solution

In case someone finds useful:

 <script type='text/javascript'>
    var options = {
        currentPage:@Html.DisplayFor(modelItem => modelItem.Sessionstateadminroot.CourseCurrentPage),
        totalPages:@Html.DisplayFor(modelItem => modelItem.Sessionstateadminroot.CourseTotalPages),
        numberOfPages:4,
        onPageChanged: function(e,oldPage,newPage){

        },
        pageUrl: function(type, page, current) {
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top