错误jQuery模板脚本中出现意外字符'$'

时间:2014-04-17 12:20:22

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

我在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会在 $ 符号上生成错误。

意外字符'$'

我该怎么做才能删除此错误?我在这里失踪了什么?

1 个答案:

答案 0 :(得分:4)

您不能将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>