dotnet / dotnet/aspnetcore

Razor Pages ConfigureFilter does not work on Areas

Open
#9,783 0 comments 1 reaction 0 assignees View on GitHub
affected-very-few area-ui-rendering enhancement feature-mvc-application-model severity-minor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is your feature request related to a problem? Please describe.
Configuring Filters for Razor Pages does not work on areas.
i.e. the following will not work for areas:
`options.Conventions.ConfigureFilter(model => new AdminDomainFilterFactory(model));`

### Describe the solution you'd like
I think it should be added to the documentation.
that this is not possible.

Currently a workaround would be adding that:
```
public static IPageApplicationModelConvention ConfigureAreaFilter(
this PageConventionCollection conventions,
string areaName,
Func factory)
{
if (areaName == null)
throw new ArgumentNullException(nameof(areaName));
if (conventions == null)
throw new ArgumentNullException(nameof (conventions));
if (factory == null)
throw new ArgumentNullException(nameof (factory));
return conventions.AddAreaFolderApplicationModelConvention(areaName, "/", (Action) (model => model.Filters.Add(factory(model))));
}
```

a better solution of course would be if it would work on **all** areas

which is possible by implementing a `IPageApplicationModelConvention` that does not filter out the areaName.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.