我在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会在 $ 符号上生成错误。
意外字符'$'
我该怎么做才能删除此错误?我在这里失踪了什么?
答案 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>