I have a view that contains lots of smaller partial views to display many different types of tabular data.
It uses a model that contains many sub models. e.g. classroom would be the model, students would be a sub-model or nested class.
sometimes a class would not contain any students. thus the ienumerable of students would be null. The problem is that partials do not allow null objects thus throwing an exception.
Here is an example....
Main view:
@Html.Partial("Partials/_Students", Model.Students)
Partial view
<div class="col-xs-12 col-sm-5 col-md-5 col-lg-5 widget-container-span">
<div class="widget-box">
<div class="widget-header header-color-dark">
<h5 class="bigger lighter">
<i class="icon-table"></i>
Notes
</h5>
<div class="widget-toolbar">
<a class="plus-sign-link" href ="@Url.Action("AddNewStudent", "Classroom")"><i class="icon-plus-sign bigger-170"></i></a>
</div>
</div>
<div class="widget-body">
<div class="widget-main no-padding">
<table class="table table-striped table-bordered table-hover" data-provides="rowlink">
<thead class="thin-border-bottom">
<tr>
<th><i class="icon-user"></i>Contact Name</th>
<th>Email </th>
<th>Telephone</th>
<th class="hidden-480">Mobile</th>
<th class="hidden-480"></th>
</tr>
</thead>
@foreach (var item in Model)
{
<tbody data-link="row" class="rowlink">
<tr>
<td>
<a href="@Url.Action("Classroom", "StudentDetails", new { @siteid = item.SiteId, @id = item.Id })">@item.Name</a>
</td>
<td class="rowlink-skip">
<a href="mailto:@item.EmailAddress">@item.EmailAddress</a>
</td>
<td class="rowlink-skip">
<a href="tel:@item.TelephoneNumber">@item.TelephoneNumber</a>
</td>
<td class="hidden-480 rowlink-skip">
<a href="tel:@item.MobileNumber">@item.MobileNumber</a>
</td>
<td class="hidden-480 rowlink-skip">
@if (item.IsDefault)
{ <span style="display: block;" class="label label-success">Default</span> }
else
{ <a style="display:block;" class="btn btn-minier btn-info" data-id="@item.Id">Make default</a> }
</td>
</tr>
</tbody>
}
</table>
</div>
</div>
</div>
Is there an extension to allow this?