【问题标题】:error Unexpected character '$' in jQuery template script错误 jQuery 模板脚本中出现意外字符“$”
【发布时间】:2014-06-01 17:05:30
【问题描述】:

我正在使用 mvc 4 C#.net 4.0、Visual Studio 2013。

我正在使用 jQuery 模板。因为我是 mvc 和 jquery 以及模板的新手

这是我的模板脚本。

我已经添加了这个

<script src="~/Scripts/jquery.tmpl.js"></script>
<script src="~/Scripts/jquery.tmpl.min.js"></script>

<script type="text/x-jquery-tmpl" id="ScheduleRowTemplate">
    <tr>
        <td>
            @Html.Label("", ${RowNo}, new { style = "width:100%" })
            <input type="hidden" id="ItemIndex" value="${ItemIndex}" />
        </td>
    </tr>
</script>

在此脚本中,Visual Studio 在 $ 标志上生成错误。

意外字符“$”

我应该怎么做才能消除这个错误?我在这里缺少什么?

【问题讨论】:

    标签: c# jquery asp.net-mvc-4 visual-studio-2013 jquery-templates


    【解决方案1】:

    您不能将Html.Label 之类的服务器端方法与${RowNo} 之类的客户端变量混合使用。使用 HTML 标记而不是 Razor 助手:

    <script type="text/x-jquery-tmpl" id="ScheduleRowTemplate">
        <tr>
            <td>
                <label style="width: 100%">${RowNo}</label>
                <input type="hidden" id="ItemIndex" value="${ItemIndex}" />
            </td>
        </tr>
    </script>
    

    【讨论】:

      猜你喜欢
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-16
      • 2016-02-19
      • 2023-02-07
      • 2012-03-03
      相关资源
      最近更新 更多