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) #39416

Merged
merged 1 commit into from
Jan 10, 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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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;
}
}
}
Original file line number Diff line number Diff line change
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