Asp.net mvc .net模板';如果为空';签入vb-语法?
我对.net完全是新手,我只需要知道语法,或者在if语句中放入可能的函数,以检查Asp.net mvc .net模板';如果为空';签入vb-语法?,asp.net-mvc,templates,syntax,if-statement,Asp.net Mvc,Templates,Syntax,If Statement,我对.net完全是新手,我只需要知道语法,或者在if语句中放入可能的函数,以检查是否不正确 其中Model.contacts来自我的ClientViewModel,而Model.contacts的类型为System.Linq.IQueryable(of Contact) 这是地址的代码 <% If Model.addresses Is Nothing Then %> <table class="edit"> <tr>
是否不正确
其中Model.contacts
来自我的ClientViewModel,而Model.contacts
的类型为System.Linq.IQueryable(of Contact)
这是地址的代码
<% If Model.addresses Is Nothing Then %>
<table class="edit">
<tr>
<td>
There are no Addresses associated with this Client, click the 'Create' Button to add contacts.
</td>
</tr>
</table>
<% Else%>
<table class="child">
<tr>
<th>
Actions
</th>
<th>
Street
</th>
<th>
City
</th>
<th>
State
</th>
<th>
Country
</th>
<th>
Zip
</th>
</tr>
<% For Each item In Model.addresses%>
... shows more table rows...
<% Next%>
</table>
<% End If%>
模板是
<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage(Of TotallyAwesomeCRM.ClientViewModel)" %>
List item
列表项
您可以尝试此操作,但请确保模型已初始化,否则可能会出现NullReferenceException
:
<% If Model.contacts Is Nothing Then %>
<div>no contacts</div>
<% End If %>
没有联系人
无/Null和空(计数=0)之间存在差异。因此,您可能需要检查这两种情况:
<% If Model.contacts Is Nothing
' do something
Else
If Model.contacts.Count = 0 Then
' do something
Else
' do something
End If
End If
%>
如果Model.contacts什么都不是-不起作用我怎么知道我是否有NullReferenceException
我读了一些关于它的文章,我不确定这是我的问题?请看编辑…计数是我需要的谢谢!
<% If Model.contacts Is Nothing
' do something
Else
If Model.contacts.Count = 0 Then
' do something
Else
' do something
End If
End If
%>