首页 新闻 会员 周边

MVC中使用jquery-tmpl出错

0
悬赏园豆:10 [已关闭问题] 关闭于 2014-11-13 16:08

在线等···

 

在webform测试是完全没问题的,但是把代码粘贴到mvc项目中就报错,上代码,求解决!

@{
    ViewBag.Title = "学院列表";
}
@*<script src="~/Scripts/MyTmpl/jquery-1.8.2.js"></script>
<script src="~/Scripts/MyTmpl/jquery.tmpl.js"></script>
<script src="~/Scripts/MyTmpl/jquery-ui-1.8.24.js"></script>*@
@*<script src="@Url.Content("~/Scripts/MyTmpl/jquery-ui-1.8.24.js")"></script>
<script src="@Url.Content("~/Scripts/MyTmpl/jquery.tmpl.js")"></script>
<script src="@Url.Content("~/Scripts/MyTmpl/jquery-ui-1.8.24.js")"></script>*@
@*<script type="text/x-jquery-tmpl" id="trTemp">
    <tr>
        <td>${Fid}</td>
        <td>${FName}</td>
        <td>${FAge}</td>
        <td>${FClassId}</td>
        <td><a href="#">删</a><a href="#">改</a></td>
    </tr>
</script>*@
<script id="myTemplate" type="text/x-jquery-tmpl">
    <tr>
        <td>${ID}</td>
        <td>${Name}</td>
    </tr>
</script>

<script type="text/javascript">
    $(function () {
        //关闭浏览器缓存
        $.ajaxSetup({ cache: false });
        //请求第一个数据
        loadPageList(1);
    });
    function loadPageList(pageIndex) {
        $.getJSON("/Stu/List/" + pageIndex, null, function (jsonData) {
            if (jsonData.Statu == "ok") {
                alert('第一个');
                var users = [{ ID: 'think8848', Name: 'Joseph Chan' }, { ID: 'aCloud', Name: 'Mary Cheung' }];
                $('#myTemplate').tmpl(users).appendTo('#rows');
                alert('第2个');
                //$('#trTemp').tmpl(jsonData.Data.PageData).appendTo("#tbBody");
                alert('第3个');
                //for (var i = 0; i < jsonData.Data.PageData.length; i++) {
                //    $('<tr><td>' + jsonData.Data.PageData[i].Fid + '</td><td>' + jsonData.Data.PageData[i].FName + '</td><td>' + jsonData.Data.PageData[i].FClassId + '</td><td>' + jsonData.Data.PageData[i].FGender + '</td><td><a href="#">删</a><a href="#">改</a></td></tr>').appendTo('#tbList');
                //}
                //        alert(jsonData.Data.PageData);
                //       $("#trTemp", jsonData.Data.PageData).appendTo('#tbList');
                //$('#trTemp').tmpl(jsonData.Data.PageData).appendTo("#tbList>tbody");
                //alert('结束了');
            }
        });
    }
</script>

@*<table id="tbList" style="width:300px;height:200px">
    <thead>
        <tr style="text-align: center; font-size: larger; font-weight: bolder;">
            <th>ID</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>班级</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody id="tbBody"></tbody>
</table>*@
<table style="width:300px;height:200px" cellspacing="0" cellpadding="3" border="1">
    <tbody id="rows"></tbody>
</table>
View Code
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    <script src="~/Scripts/MyTmpl/jquery-1.8.2.js"></script>
    <script src="@Url.Content("~/Scripts/MyTmpl/jquery.tmpl.js")"></script>
    <script src="@Url.Content("~/Scripts/MyTmpl/jquery-ui-1.8.24.js")"></script>

    <style type="text/css">
        #tbList {
            border: 1px solid #0094ff;
            width: 400px;
            border-collapse: collapse;
        }

            #tbList td, #tbList th {
                border: 1px solid #0094ff;
                padding: 2px;
            }
    </style>
    @RenderSection("headSection", required: false)
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>
    @RenderBody()

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

未经处理的异常,行 53,列 17,在 http://localhost:19505/ 中

0x800a01b6 - JavaScript 运行时错误: 对象不支持“tmpl”属性或方法

若云的主页 若云 | 菜鸟二级 | 园豆:214
提问于:2014-11-13 16:06
< >
分享
所有回答(2)
0

已经解决,操

若云 | 园豆:214 (菜鸟二级) | 2014-11-13 16:08
0

怎么解决的我也遇到了相同的问题

hnl | 园豆:202 (菜鸟二级) | 2015-04-23 15:39

时间太久了 具体怎么弄的我也忘了,不过你要注意 js文件的加载顺序 ,还有 版本问题。

支持(0) 反对(0) 若云 | 园豆:214 (菜鸟二级) | 2015-04-23 16:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册