gpt4 book ai didi

asp.net-mvc-3 - ASP.NET MVC3 Razor : Is it possible to have C# code blocks without @if or @foreach?

转载 作者:行者123 更新时间:2023-12-04 13:20:52 27 4
gpt4 key购买 nike

我还没有真正找到通过 SO 搜索的解决方案。

...并怀疑我真的应该在模型中这样做...

但是是否可以在其中添加临时代码的 C# 代码块,例如:

@int daysLeft = CurrentTenant.TrialExpiryDate.Subtract(DateTimeOffset.Now).Days
@if (daysLeft <= 0) {
{
<text>
Trial period completed
</text>
}
else
{
<text>
You have @daysLeft days left of you trial
</text>
}

最佳答案

是的:

@{
var one = 1;
var two = one + one;
}

Phil Haack 有一个非常受欢迎的 blog post总结 Razor 语法。

关于asp.net-mvc-3 - ASP.NET MVC3 Razor : Is it possible to have C# code blocks without @if or @foreach?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6361171/

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