ASP.NET MVC 4 Razor如果有多个视图变量不显示空格

时间:2014-05-08 03:06:39

标签: asp.net asp.net-mvc asp.net-mvc-4 razor

我在Razor View中有以下代码......

@foreach (var c in Model.customerList)
{ 
<tr>
<td>
@c.customerData.firstName @c.customerData.lastName
</td>
<td>

@if (@c.customerData.address1 != null || (@c.customerData.zip != null && @c.customerData.city != null))
{ 
    @c.customerData.address1 @c.customerData.address2 @c.customerData.city @c.customerData.state @c.customerData.zip         
}
else
{ 
    @:N/A
}

</td>

<td>
    pets
</td>

<td>
    appointments
</td>

<td>
    act
</td>

}

然后显示if语句中的模型值之间没有空格.....

输出HTML就是这样的。我发誓此前已经奏效。我做错了什么?

<tr>
<td>
Barack Obama
</td>
<td>
1 Pennsylvania AveWashington220001                          
</td>
<td>
pets
</td>
<td>
appointments
</td>
<td>
act
</td>
</tr>
<tr>
<td>
Name
</td>
<td>
N/A
</td>
<td>
pets
</td>
<td>
appointments    
</td>
<td>
act
</td>
</tr>

更新

修正:

@if (@c.customerData.address1 != null || (@c.customerData.zip != null && @c.customerData.city != null))
{ 
<td>
@c.customerData.address1 @c.customerData.address2 @c.customerData.city @c.customerData.state @c.customerData.zip         
<td>

}
else
{ 
<td>

N/A
</td>

}   

0 个答案:

没有答案