Skip to content

Commit

Permalink
Avoid declaring RazorPage<T>.Model as nullable by default (#39332) (#…
Browse files Browse the repository at this point in the history
…39416)

Contributes to #37510
  • Loading branch information
pranavkm committed Jan 10, 2022
1 parent d9521ac commit 2bd9de6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/Mvc/Mvc.Razor/src/PublicAPI.Unshipped.txt
@@ -1 +1,3 @@
#nullable enable
*REMOVED*Microsoft.AspNetCore.Mvc.Razor.RazorPage<TModel>.Model.get -> TModel?
Microsoft.AspNetCore.Mvc.Razor.RazorPage<TModel>.Model.get -> TModel
3 changes: 1 addition & 2 deletions src/Mvc/Mvc.Razor/src/RazorPageOfT.cs
Expand Up @@ -15,13 +15,12 @@ public abstract class RazorPage<TModel> : RazorPage
/// <summary>
/// Gets the Model property of the <see cref="ViewData"/> property.
/// </summary>
public TModel? Model => ViewData == null ? default(TModel) : ViewData.Model;
public TModel Model => ViewData.Model;

/// <summary>
/// Gets or sets the dictionary for view data.
/// </summary>
[RazorInject]
public ViewDataDictionary<TModel> ViewData { get; set; } = default!;

}
}
2 changes: 2 additions & 0 deletions src/Mvc/Mvc.ViewFeatures/src/PublicAPI.Unshipped.txt
@@ -1 +1,3 @@
#nullable enable
*REMOVED*Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<TModel>.Model.get -> TModel?
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<TModel>.Model.get -> TModel
12 changes: 3 additions & 9 deletions src/Mvc/Mvc.ViewFeatures/src/ViewDataDictionaryOfT.cs
Expand Up @@ -86,16 +86,10 @@ internal ViewDataDictionary(IModelMetadataProvider metadataProvider)
}

/// <inheritdoc />
public new TModel? Model
public new TModel Model
{
get
{
return (base.Model == null) ? default(TModel) : (TModel)base.Model;
}
set
{
base.Model = value;
}
get => (base.Model is null) ? default! : (TModel)base.Model;
set => base.Model = value;
}
}
}
Expand Up @@ -6,10 +6,10 @@
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model?.ShowRequestId ?? false)
@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model?.RequestId</code>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

Expand Down

0 comments on commit 2bd9de6

Please sign in to comment.