0

我收到用于 Telerik 网格实现的 javascript 错误“JQuery undefined”,我不明白同样的原因。我确实包含了所有可能的 JQuery 文件,但仍然出现 Javascript 错误。

下面是我实现的示例代码。

<script src="@Url.Content("~/Scripts/jquery-1.7.1.js")" type="text/javascript"></script>

@(Html.Telerik().Grid(Model.Employee)
                                                    .HtmlAttributes(new { style = "width:100%;" })
                                                .Name("Employee")
                                                .DataKeys(keys =>
                                                {
                                                    keys.Add(m => Id);

                                                })

                                                .Columns(columns =>
                                                {

                                                    columns.Bound(p => p.Name).Title("Name")
                                                        .HeaderHtmlAttributes(new { width = "110px", style = "text-align:center;font-weight:bold;height:auto" })
                                                    .HtmlAttributes(new { width = "110px", style = "text-align:left;height:auto" });
                                                    columns.Bound(p => p.ReportedStatus).ClientTemplate("<#= ReportedStatus(data) #>").Title("Reported")
                                                         .HeaderHtmlAttributes(new { width = "130px", style = "text-align:center;font-weight:bold;height:auto" })
                                                    .HtmlAttributes(new { width = "130px", style = "text-align:center;height:auto" });
                                                    columns.Bound(p => p.status).Title("status").ClientTemplate("<#=status(data) #>")
                                                        .HeaderHtmlAttributes(new { width = "130px", style = "text-align:center;font-weight:bold;height:auto" })
                                                    .HtmlAttributes(new { width = "130px", style = "text-align:center;height:auto" });
                                                    columns.Bound(p => p.Hrs).Title("Hrs")
                                                        .HeaderHtmlAttributes(new { width = "150px", style = "text-align:center;font-weight:bold;height:auto" })
                                                    .HtmlAttributes(new { width = "150px", style = "text-align:center;height:auto" });
                                                    columns.Bound(l => l.Location).ClientTemplate("<#= Location(data) #>").Title("Location")
                                                         .HeaderHtmlAttributes(new { width = "200px", style = "text-align:center;font-weight:bold;height:auto" })
                                                    .HtmlAttributes(new { width = "200px", style = "text-align:center;height:auto" });
                                                    columns.Bound(l => l.Role).ClientTemplate("<#= Role(data) #>").Title("Role")
                                                        .HeaderHtmlAttributes(new { width = "150px", style = "text-align:center;font-weight:bold;height:auto" })
                                                    .HtmlAttributes(new { width = "150px", style = "text-align:center;height:auto" });

                                                }).Footer(false)
                                                                          )
<script type="text/javascript" src="@Url.Content("~/Scripts/telerik.common.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/telerik.textbox.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/telerik.grid.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/telerik.draganddrop.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/telerik.window.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/telerik.grid.editing.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/telerik.upload.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/telerik.menu.js")"></script>

@(Html.Telerik().ScriptRegistrar()
                 .jQuery(false)
                 .DefaultGroup(group => group
                 .Add("telerik.examples.min.js")
                 .Add("telerik.grid.js")
                 .Compress(false)
                 .Combined(true))
                 .OnDocumentReady(
                 @<text> prettyPrint();
</text>)
)

请让我知道我在这里为这个 JQuery 错误做错了什么。

提前致谢, Maanoj

4

1 回答 1

0

看起来您没有正确包含文件。如果你的字符串中有双引号,解析器会认为它是字符串的结尾,而不是正确地解释字符串。您需要转义它们或在内部使用单引号。.

代替

src="@Url.Content("~/Scripts/jquery-1.7.1.js")"

尝试

src="@Url.Content('~/Scripts/jquery-1.7.1.js')"

         OR
src="@Url.Content(\"~/Scripts/jquery-1.7.1.js\")"

您也可以通过转义双引号来实现相同的目的,因为解析器可能认为它是介于 " " 之间的字符串的结尾

于 2012-10-08T08:26:06.413 回答