如何在 asp.net razor 中使用 html 中的 if 子句代码?
how use if clause code within html in asp.net razor?
我想在剃须刀中编写“if 子句”,例如
@if (ViewBag.name == null)
{
<h3> name is empty.... </h3>
@} else {ViewBag.name }
但我收到错误!
你能帮帮我吗
@ 用于开始编写 razor 语句,即 C# 代码,在 html 中我们仍然可以使用以 @[=20 开头的 razor 语句=]
以下是它的正确语法:
@if (ViewBag.name == null)
{
<h3> name is empty.... </h3>
}
else
{
<h3>@ViewBag.name</h3>
}
它可以像下面这样更简化:
<h3> @(ViewBag.name == null ? "name is empty...." : ViewBag.name) </h3>
我想在剃须刀中编写“if 子句”,例如
@if (ViewBag.name == null)
{
<h3> name is empty.... </h3>
@} else {ViewBag.name }
但我收到错误! 你能帮帮我吗
@ 用于开始编写 razor 语句,即 C# 代码,在 html 中我们仍然可以使用以 @[=20 开头的 razor 语句=]
以下是它的正确语法:
@if (ViewBag.name == null)
{
<h3> name is empty.... </h3>
}
else
{
<h3>@ViewBag.name</h3>
}
它可以像下面这样更简化:
<h3> @(ViewBag.name == null ? "name is empty...." : ViewBag.name) </h3>