简体   繁体   中英

error Unexpected character '$' in jQuery template script

I am working in mvc 4 C#.net 4.0, Visual Studio 2013.

I am using jQuery template. As i am new to mvc and jquery and also for template

Here is my script for template.

I have add this

<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>

In this script, Visual Studio generating error on $ signs.

Unexpected character '$'

What should i do to remove this error? which thing i am missing here ?

You can't mix a server-side method like Html.Label with a client-side variable like ${RowNo} . Use HTML markup instead of the Razor helpers:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM