【发布时间】:2022-12-18 15:28:59
【问题描述】:
嗨,我又有问题了。是否可以在剃须刀页面中基于 C# 值呈现 js 代码?我该怎么做?例如:
@{
double numberA = (double)ViewData["someVal"];
}
<h1>SOME HTML</h1>
<script>
let myVal = "Number is small";
@if (numberA > 5) { // C# code checking c# variable that comes via ViewModel fom server
myVal = "Number is large" // change js variable
}
console.log(myVal); // prints phrase to browser console based on what was received from backend
</script>
基本情况如上
【问题讨论】:
标签: javascript asp.net-core model-view-controller razor viewdata