2011-07-29 72 views
1

Tablesorter不适用于Visual Studio 2010上的MVC3 Web应用程序?Tablesorter不适用于Visual Studio 2010上的MVC3 Web应用程序

要重现该问题:

  • 打开Visual Studio 2010中
  • 创建一个新的ASP.NET MVC 3 Web应用程序
  • 更换次数/共享/ _Layout.cshtml有:

    <!DOCTYPE html> 
    <html> 
    <head> 
        <title>@ViewBag.Title</title> 
        <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> 
    
    @* This doesn't work and I don't know why *@ 
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/jquery.tablesorter.min.js")" type="text/javascript"></script> 
    
    @*This works*@ 
    @*<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> 
    *@ 
    
    </head> 
    <body> 
        <div class="page"> 
    
        <div id="main"> 
         @RenderBody() 
        </div> 
        </div> 
    </body> 
    </html> 
    
  • 将视图/主页/ Index.html替换为:

    <h2>debug jquery Kano</h2> 
    <p> 
        testing 
    </p> 
    
    <table id="theTable" class="tablesorter"> 
    <thead> 
        <tr><th>Tic</th><th>Tac</th><th>Toe</th></tr> 
    </thead> 
    <tbody> 
        <tr><td>o</td><td>o</td><td>x</td></tr> 
        <tr><td>x</td><td>o</td><td>o</td></tr> 
        <tr><td>o</td><td>x</td><td>x</td></tr> 
    </tbody> 
    </table> 
    
    <script type="text/javascript"> 
    // $(function() { 
    //  alert("$: jQuery found!"); 
    // }); 
    
        $(document).ready(function() { 
         $("#theTable").tablesorter(); 
        }); 
    </script> 
    
  • http://tablesorter.com下载jquery.tablesorter.min.js并放入/ Scripts目录。

  • 构建并运行应用程序。

正如您将希望看到的那样,Index.cshtml中的tablesorter调用似乎没有成功执行。

谢谢你的帮助!

干杯, 凯文

回答

0

的问题似乎是在JavaScript是缓存的方式。解决方法是在运行之间关闭浏览器的所有实例,并尽量减少浏览器上后退按钮的使用。

3

百威做的就是添加tablesorter.js到bundleconfig.cs喜欢这个 -

bundles.Add(new ScriptBundle("~/bundles/jquery.tablesorter").Include("~/Scripts/jquery.tablesorter.js")); 

在 _layout.cshtml页面添加CSS-

@Styles.Render("~/Content/css") 
     @Scripts.Render("~/bundles/modernizr") 
      <link href="@Url.Content("~/Content/style.css")" rel="stylesheet" type="text/css" /> 
     </head> 

并在底部添加脚本像

</footer> 

     @Scripts.Render("~/bundles/jquery") 
     @Scripts.Render("~/bundles/jqueryui") 
     @RenderSection("scripts", required: false) 
    </body> 
</html> 

并在页面上使用添加一个会话它..所以你不必使用电子非常单页

@section scripts 
{ 
    @Scripts.Render("~/bundles/jquery.tablesorter") 
    <script type="text/javascript">  

     $(document).ready(function() { 
      $("#myTable").tablesorter(); 
     }); 

     $(document).ready(function() {   
      $("#myTable").tablesorter({ sortList: [[0, 0], [1, 0]] }); 
     }); 
    </script> 
} 
相关问题