gpt4 book ai didi

javascript - Razor 在 javascript 中查看 if/else 语句

转载 作者:行者123 更新时间:2023-11-30 07:37:53 25 4
gpt4 key购买 nike

是否可以在 razor View 中执行此操作。我只想在语句为真时注入(inject)下面的 JavaScript,否则不注入(inject)。我该怎么做。

            @if (Model.EmployeeInterviews != null)
{
$("#select-Candidate")[0].selectize.setValue(@Html.Raw(JsonConvert.SerializeObject(Model.CandidateId)));
var employee = @Html.Raw(JsonConvert.SerializeObject(selectedempobj));
var val = "[";
for (i = 0; i < employee.length; i++)
{
val += employee[i].EmployeeID + ",";
}
val = val.substring(0, val.length - 1) + "]";

$("#select-Employee")[0].selectize.setValue(JSON.parse(val));
$('#txtScheduledOn').val('@String.Format("{0:M/d/yyyy HH:mm tt}", Model.ScheduledOn)');
$('#txtCompletedOn').val('@String.Format("{0:M/d/yyyy HH:mm tt}", Model.CompletedOn)');
$('#hdnEmployeeId').val(JSON.parse(val).toString());
$('#hdnCandidateId').val('@Html.Raw(JsonConvert.SerializeObject(Model.CandidateId))');
}

最佳答案

像这样

<script type="text/javascript">
$(document).ready(function () {
//... some common javascript

@{
if (Model.EmployeeInterviews != null) {
<text>
$("#select-Employee")[0].selectize.setValue(JSON.parse(val));
$('#txtScheduledOn').val('@String.Format("{0:M/d/yyyy HH:mm tt}", Model.ScheduledOn)');
//... specific javascript
</text>
}
}
});
</script>

关于javascript - Razor 在 javascript 中查看 if/else 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26778932/

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