[英]How to Insert an Inline Razor Expression into Javascript
I have the following script: 我有以下脚本:
<script type="text/javascript">
function addRow() {
var count = $("#tblUploadDocs").prop('rows').length;
count += 1;
alert(count);
var html = '<tr>';
html += '<td><input type="file" name="files" id="file' + count + '" /></td>';
html += '<td>Bu dilden</td>';
html += '<tr>';
alert(html);
}
</script>
I am trying to insert the following line into the script, but could not achieve the desired result: 我正在尝试将以下行插入脚本,但是无法达到预期的结果:
<td>@Html.DropDownList("ddlFromLanguage1", ViewBag.Languages as SelectList)</td>
I tried both and @: but could not make it work. 我和@:都尝试了,但是无法正常工作。 I am looking forward to hearing to a solution.
我期待听到解决方案。
Thanks in advance 提前致谢
Use the <text>
pseudo-element, as described here , to force the razor compiler back into content mode: 使用
<text>
伪元素,如所描述这里 ,以迫使剃刀编译器返回到内容模式:
<script type="text/javascript">
function addRow() {
<text>
var count = $("#tblUploadDocs").prop('rows').length;
count += 1;
alert(count);
var html = '<tr>';
html += '<td><input type="file" name="files" id="file' + count + '" /></td>';
html += '<td>Bu dilden</td>';
html += '<tr>';
alert(html);
</text>
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.