使用RazorViewEngine,我可以这样做:
if (somecondition) {
<div> some stuff </div>
}
Run Code Online (Sandbox Code Playgroud)
但我似乎无法做到这一点(Razor感到困惑):
if (somecondition) {
<div>
}
if (someothercondition) {
</div>
}
Run Code Online (Sandbox Code Playgroud)
我有一种情况需要将我的开始和结束html标签放在不同的代码块中 - 我怎样才能在Razor中执行此操作?
@if (Model.Property != null)
{
<text>
<div class="row">
</text>
Html.RenderPartial("~/Views/CustomView.cshtml", Model);
<text> (line throwing error)
</div>
</text>
}
Run Code Online (Sandbox Code Playgroud)
错误:"文本"元素未关闭.所有元素必须是自动关闭或具有匹配的结束标记."
我很难理解为什么第二组<text>标签会返回该错误.任何帮助理解它将不胜感激.