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

List template: guard against null metadata #1774

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/Scaffolding/VS.Web.CG.Mvc/MessageStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,7 @@
<data name="IdentityNotSupported" xml:space="preserve">
<value>Scaffolding Identity is not supported for web applications with minimal APIs for hosting and routing.</value>
</data>
</root>
<data name="ModelMetadataRequired" xml:space="preserve">
<value>This template requires a database context.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@
@:<p>
@:<a asp-page="Create">Create New</a>
@:</p>
if (((IModelMetadata)Model.ModelMetadata) is IModelMetadata metadata) {
var propertyLookup = metadata.Properties.ToDictionary(x => x.PropertyName, x => x);
var navigationLookup = metadata.Navigations.ToDictionary(x => x.AssociationPropertyName, x => x);
@:<table class="table">
@:<thead>
@:<tr>
Dictionary<string, IPropertyMetadata> propertyLookup = ((IModelMetadata)Model.ModelMetadata).Properties.ToDictionary(x => x.PropertyName, x => x);
Dictionary<string, INavigationMetadata> navigationLookup = ((IModelMetadata)Model.ModelMetadata).Navigations.ToDictionary(x => x.AssociationPropertyName, x => x);

foreach (var item in Model.ModelMetadata.ModelType.GetProperties())
{
Expand Down Expand Up @@ -107,6 +108,8 @@
@:</tbody>

@:</table>
}
else throw new ArgumentNullException (nameof (Model.ModelMetadata), "This template requires a database context.");
if(!Model.IsPartialView && !Model.IsLayoutPageSelected)
{
//ClearIndent();
Expand Down