简体   繁体   中英

How do you pass values to javascript in view template in MVC5?

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.

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) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM