SA1649 conflicts with default Razor Pages file/class naming
See original GitHub issueWhen creating a Razor Page it will generate a .cshtml
and .cshtml.cs
files. The model used inside this file is postfixed with Model
, which causes SA1649 to be violated.
Eg: When creating a Razor Page called Index
, the files generated will be called Index.cshtml
and Index.cshtml.cs
, but the class generated will be called IndexModel
.
Not sure if this case should be allowed in SA1649, as I don’t want to switch this rule off for the whole project and adding #pragma warning disable/restore
to every Razor Page seems excessive to me?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Disable SA1649 for file names that contain a period · Issue ...
Given a class "ClassName" and a filename of "ClassName.Generated.cs", I think this should be valid for the rule. I believe it's a common ......
Read more >Razor page namespace conflicts with class library
I have a razor page with a namespace like MyApp.Pages.MyClass . Within this page cshtml I am trying to reference an enum in...
Read more >Changing the Default Page in ASP.NET Core Razor Pages
Hello, After I created some Razor Pages in our app, I changed Root directory from Pages to My. Now how can I change...
Read more >If my solution is totally based on razor page and partial ...
I'm assuming here that your razor pages are not conflicting with the controllers. If they are then the wrong code is getting called....
Read more >Razor Pages for ASP.NET Core - Full Course (.NET 6)
Learn the basics of Razor Pages for ASP. ... Custom Validations ⌨️ (2:09:38) Display Name and Range Annotation ⌨️ (2:12:58) Client Side ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@daviddunson That should be possible using .editorconfig in 16.3.
@sharwell
I know I’m late to the party here, but your suggestion #2 would break the convention that’s been in place since the beginning of MVC where model classes end with the Model suffix to distinguish from similarly named objects (usually entities), #3 requires also renaming the .cshtml file, which is part of the URL.
The gotcha here is that in traditional MVC, the cshtml files had no code-behind & the models live in a separate folder… now with Razor Pages the model is the code-behind, which for many scenarios is much cleaner by having related pieces together, but does break this rule as the two long-standing conventions now conflict with each other.
It would be nice if rulesets could apply by subfolder instead of strictly at the project level, but I have a hunch the amount of effort required to make that happen means I’m not likely to see it anytime soon.
Meantime, as ugly as it is, I’m setting my convention to be the first line of all Razor Page code behinds/models is
#pragma warning disable SA1649
.