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

RuleSetForClientSideMessagesAttribute for Razor Pages PageModel #1544

Closed
DavidJohnWilliams opened this issue Oct 9, 2020 · 2 comments
Closed
Milestone

Comments

@DavidJohnWilliams
Copy link
Contributor

Hi Jeremy,

I have a potential resolution for this one as well but I thought it best to open some discussion first.

The current RuleSetForClientSideMessagesAttribute cannot be used with Razor Pages as it is an ActionFilter.

Option 1

Use a PageFilter which is added for all pages. This then checks for the presence of the RuleSetForClientSideMessagesAttribute and sets the value in HttpContext accordingly.

I have tested this it works fine. Quite neat actually and requires no changes to the current attribute. One possible issue is that it will call the filter for all pages unless the developer specifies which pages to run it for.

It could possibly be added in FluentValidationMvcExtensions via configuration.

Option 2

Add a new attribute e.g. PageModelRuleSetForClientSideMessagesAttribute which inherits ResultFilterAttribute and does the same thing as the RuleSetForClientSideMessagesAttribute.

This also passes tests and doesn't require any addition config. But of course requires a different attribute and can only be applied for the whole page and all handlers.

Conclusion

I think it might be worth implementing both and updating the documentation accordingly. If you would prefer only one or the other let me know and I will adjust before submitting the PR.

Also are you happy for me to to the docs update this time to save you having to do it?

And are you happy if I add some configuration options to the FluentValidationMvcExtensions to allow adding the page filter or would you prefer to just leave it to developers to add manually and just document it?

Best regards

Dave

@JeremySkinner
Copy link
Member

Hi Dave, I think I prefer option 1, so let’s go for that if you’d like to implement it. Let’s
enable it by default (in the RegisterServices method I think) - I’m not sure whether it really needs a config option to disable it, but let’s add one anyway.

@JeremySkinner JeremySkinner added this to the 9.3 milestone Oct 14, 2020
@JeremySkinner
Copy link
Member

The .net5 branch has been merged into master, and this will be included in the 9.3 release.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants