gpt4 book ai didi

javascript - 如何在 MVC 的 Razor 语法中的 Jscript 中使用 "@"符号?

转载 作者:行者123 更新时间:2023-11-28 20:50:32 32 4
gpt4 key购买 nike

我正在使用 Razor 语法开发 MVC 3 应用程序。

我正在 cshtml 文件中写入 Jscript...我想在 JScript 中使用 @,但它显示黄色背景。

我想将整数值分配给按钮 ID,该怎么做?

这是代码...

  success: function (data) {

$("p.p12").append

("<div style=\"background-color:#FAFAFA\";>Recently Added... <br /><a href=\"../../Employee/Details/" + data.OwnerID + "\">" + data.OwnerName + "</a>"
+ data.cmtDateTime + " <span class=\"EmpName\"><button type=\"button\" id = \" @item.Id \"class=\"deleteComment\">Delete</button></span> <br />" + data.msg + "</div>");

document.getElementById('Comment').value = "";
$(".ParentBlock").slideDown("slow");
$(".ParentBlock").attr("DataCommentId",data.Id);


$('.ShowComments').text('Hide Comments');

}

这是图片...

enter image description here

我应该对@符号做什么?

最佳答案

您当前的代码是正确的。运行它,你会发现它可以工作。就黄色曲线而言,忽略它并停止信任自动代码编辑器,相信您编写的代码 - Razor Intellisense 远非完美。希望他们会在未来的版本中改进它。

作为构建此元素的替代方法,您可以使用以下内容,因为您的代码一团糟(例如,属性之间没有空格,您已经颠倒了 ;,...):

$('p.p12').append(
$('<div/>', {
style: 'background-color:#FAFAFA;',
html: 'Recently Added...'
})
.append($('<br/>'))
.append($('<a/>', {
href: '@Url.Action("Details", "Employee", new { id = "__employeeId__" })'.replace('__employeeId__', data.OwnerID),
html: data.OwnerName
}))
.append(data.cmtDateTime)
.append($('<span/>', {
'class': 'EmpName',
html: $('<button/>', {
type: 'button',
id: '@item.Id',
'class': 'deleteComment',
html: 'Delete'
})
}))
.append($('<br/>'))
.append(data.msg)
);

关于javascript - 如何在 MVC 的 Razor 语法中的 Jscript 中使用 "@"符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12542015/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com