Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid declaring RazorPage<T>.Model as nullable by default #39332

Merged
merged 1 commit into from Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,12 +15,11 @@ 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;
pranavkm marked this conversation as resolved.
Show resolved Hide resolved
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,15 +86,9 @@ 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