【问题标题】:Why won't datatables plug-in not work for my ASP.NET MVC 4?为什么数据表插件不适用于我的 ASP.NET MVC 4?
【发布时间】:2013-05-04 06:42:40
【问题描述】:

我想启用无限滚动。因此,我在我的 Visual Studio 2012 项目中使用 nuGet 安装了数据表插件。它是一个标准的模型、视图和控制器项目。

  1. 在包管理器控制台中运行“Install-Package jquery.datatables”
  2. 将 和 添加到视图中
  3. 在视图中添加了脚本
  4. 在 stackoverflow 上查看了类似的问题,但没有成功
  5. 问题 我正在编写一个演示来教自己无限滚动,为一个严肃的项目做准备。我有大约 30 个名字。所以它应该是我想显示前 10 个名字的地方,它可以无限滚动显示给每个人。我的项目编译没有错误。但是,当我看表时。我看到数据表插件根本没有呈现 no change。它像以前一样显示 30 个名称。

    模型-视图

     public class ISModel
    {
            //[ScaffoldColumn(false)]
            public int ID { get; set; }
    
            public String name { get; set; }
    
            public int age { get; set; }
    
            // array list of bools for displaying achievement images? if true, display image on list, else don't display (alt text for 1.g)
            //public bool[] achieve { get; set; }
    
    }
    

    控制器动作

    public ActionResult Index()
            {
                return View(db.ISModel.ToList());
                //return View();
            }
    

    布局文件

        @Styles.Render("~/Content/css")
        @Scripts.Render("~/bundles/jquery")
        @Scripts.Render("~/Scripts/jquery.dataTables.js")
        @Scripts.Render("~/bundles/modernizr")
    

    请注意,我的布局只是 MSVS2012 自动生成的。它有标准的主页 和关于按钮。以及自动生成的登录功能。

    查看

        @model IEnumerable<ISDemo.Models.ISModel>
    
    @{
        ViewBag.Title = "Index";
    }
    
    <h2>Index</h2>
    
    
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
    <table id = "demoTable">
        <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.name)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.age)
            </th>
            <th></th>
        </tr>
        </thead>
        <tbody>
    
    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.age)
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
                @Html.ActionLink("Details", "Details", new { id=item.ID }) |
                @Html.ActionLink("Delete", "Delete", new { id=item.ID })
            </td>
        </tr>
    }
         </tbody>
    
    </table>
    @section Scripts{
        <script type="text/javascript">
        $(document).ready(function(){
            $('#demoTable').dataTable({
                "bScrollInfinite": true,
                "bScrollCollapse": true,
                "sScrollY": "200px"
            });
        });
        </script>
    }
    

    【问题讨论】:

    标签: c# asp.net asp.net-mvc linq jquery-datatables


    【解决方案1】:

    首先尝试将“sScrollY”参数的值减小到一些较小的值,如果它对您有帮助,那么您应该找到一些技术来调整“sScrollY”值与父元素的高度。

    【讨论】:

      猜你喜欢
      • 2013-11-30
      • 2012-06-11
      • 2014-07-01
      • 2015-08-15
      • 1970-01-01
      • 1970-01-01
      • 2014-10-01
      • 2011-12-03
      • 2014-08-23
      相关资源
      最近更新 更多