English 中文(简体)
MVC4 拼写脚本
原标题:MVC4 jquery scripting

我习惯于 MVC2 。 您只是将您的脚本和源头链接添加到视图中, 并拨打jquery 函数和 viola... 您有正在使用的 Jquery 代码 。 但我无法使我的 jqGrid 表格 ToGrid 函数工作 。 我猜是因为我根本没有把 jquery 库装进去, 或者我没有在正确的地方运行脚本 。 您可以看一下我的代码, 看看有什么可能出错吗?

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ShowAllEncounters</title>
 <link href="@Url.Content("~/Content/jquery.jqGrid/ui.jqgrid.css")" rel="Stylesheet" type="text/css"/>
</head>

This would be the head... I previously had my scripts linked in there as well... But that didn t work... So I put outside of the tag... like so...

</html>
<script src="@Url.Content("~/Scripts/jquery.jqGrid.min.js")" type="text/javascript"/>
<script type="text/javascript">
$(document).ready(function () {
...});

我在MVC4站点怎么写剧本?

我甚至不能得到一个可怕的警报 出现!!!!!!!!!

@model IEnumerable<FocusedReadMissionsRedux.Models.TemplateModel>
<!DOCTYPE html>

<html>
<head>
<script src="@Url.Content("~/Scripts/jquery.jqGrid.min.js")" type="text/javascript"/>
<link href="@Url.Content("~/Content/jquery.jqGrid/ui.jqgrid.css")" rel="Stylesheet" type="text/css"/>
   <script type="text/javascript">
       $(document).ready(function () {
        alert("what is going on");
       });
   </script>
   <title>ShowAllEncounters</title>
</head>

更新: 似乎我对何时加载 jquery 库有疑问。 这肯定是个问题。 我需要一个坚实的图案模式, 才能把这些脚本添加到工程中?

最佳回答

在“新”的 MVC4 模板中,在_layout.cshtml 的“底部”通过 Bundles 添加jquery脚本。

将 @scripts. render ("~/bundles/jquery") 移动到 _layout.cshtml 的区块 。

我不知道为什么模板把这个脚本包含在 html 文件的结尾...

问题回答

除了Patrice的答复(只是向未来的访客澄清)之外。

套件可在/App_Start/BundleConfig.cs上定制。

正如NoProblemBabe 所说, 带有 Javascript 内容的套件被放在 html 文件的末尾, 以确保第一次访问时加载 Javascript 文件不会卡住 HTML 文件加载的其余部分, 它会更快地向客户端显示页面 。

As jQuery start functions are put in $(document).ready (in a well coding practice), there s no big deal with it. Plus, browser caching of JS files is a point to remember. (that will probably be enabled in a almost totally of browsers).





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签