1

The following statement is erring in my MVC razor view.

 @foreach (var user in Model.Users)
                {
                    <li><a href="#">Add user</a></li>
                    <li><a href="#">@user.FirstName @user.LastName 
                        if(user.FirstName != "")
                        { 
                        @(@user.UserName)
                        }else{ 
                        @user.UserName
                        }
                        </a></li>
                }

I cannot seem to figure out the razor to handle this properly.

4

1 回答 1

0

很可能您正在寻找@if而不是if因为启动 HTML 标记将上下文从“代码”切换到 HTML,并且您需要将其切换回“代码”。

@foreach(...
{
<span>...
  @if(...) 
  {
     <text>@user.UserName</text>
  }
</span>
}
于 2013-04-20T01:47:10.020 回答