简体   繁体   English

如何在MVC5的视图模板中将值传递给javascript?

[英]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? 您如何将值从模型传递到MVC中的javascript页面脚本? I have a paging model and need to pass values to the following javascript in the view template: 我有一个分页模型,需要将值传递给视图模板中的以下javascript:

  <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. 我需要在模型中传递值,以替换上述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) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将复选框的值传递给MVC5中的ActionResult? - How to pass the values of the checkboxes to ActionResult in MVC5? 如何在嵌套在视图内的部分视图内加载javascript文件? MVC5 - How do I load my javascript file inside my partial view that is nested inside a view? MVC5 如何在MVC5中由ajax调用的Partial View中引用外部javascript? - How to reference outside javascript in a Partial View called by ajax in MVC5? 如何将复选框的值从JavaScript /视图传递到MVC中的控制器? - How to pass values of checkboxes from JavaScript/view to controller in MVC? 将模型属性从视图传递到asp.net MVC5中的javascript - pass model property from view to javascript in asp.net MVC5 将值从控制器传递到mvc5中的javascript中 - Passing values from controller into javascript in mvc5 如何将脚本中定义的变量传递给 ASP.NET MVC5 剃刀视图中的除法标记? - How to pass variable defined in scripts to division tag in ASP.NET MVC5 razor view? 如何将Javascript数组传递给视图? (MVC4) - How to pass a Javascript Array to a View ? (MVC4) 如何将文本框值传递给ASP.NET MVC5中的JavaScript变量? - How to pass text box value to javascript variable in asp.net mvc5? 如何在.net MVC5控制器中编写JavaScript - How to write JavaScript in .net MVC5 controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM