Avoid NREs in MVC sample

- see e.g. results of `GET ~/Home/Post`
- use parentheses to avoid `?` confusing Razor

nit: remove unused Home/Test.cshtml view
This commit is contained in:
Doug Bunting 2014-10-27 21:33:06 -07:00
parent e54bf866e0
commit ab8a77bb70
4 changed files with 3 additions and 4 deletions

View File

@ -26,7 +26,7 @@
if (metadata != null)
{
var typeName = metadata.ModelType.Name;
var description = metadata.Description;
var description = metadata.Description ?? "no description";
<p>@typeName has description '@description' and contains</p>
<ul>
@foreach (var property in metadata.Properties)

View File

@ -1 +0,0 @@
Hello From Razor

View File

@ -1,6 +1,6 @@
@using MvcSample.Web.Models
@model User
<strong>Hello @Model.Name from Partial</strong>
<strong>Hello @(Model?.Name) from Partial</strong>
<a href="@Url.Action("Create", "Home")">Create Something!</a>

View File

@ -53,7 +53,7 @@
<p><a href="http://asp.net" class="btn btn-primary btn-large">Learn more &raquo;</a></p>
</div>
<div class="row">
<h3 title="@Model.Name" class="@nullValue">Hello @Html.DisplayTextFor(User => User)! Happy @Model.Age birthday.</h3>
<h3 title="@(Model?.Name)" class="@nullValue">Hello @Html.DisplayTextFor(User => User)! Happy @(Model?.Age) birthday.</h3>
<h3 id="qux">This value was retrieved asynchronously: @(await AsyncValueRetrieval())</h3>
<h3>Partial Async: @await Html.PartialAsync("HelloWorldPartial", Model)</h3>
<h3>