C
C#12mo ago
Shiv

razor pages vs .cshtml

Team , What is the difference between razor pages and cshtml.? razor pages looks like old asp.net web pages aspx and aspx.cs where views were tightly coupled to code behind(ASPX.CS). there was some drawbacks like tightly coupling in asp.net web forms and then comes mvc . what was the reason to bring razor pages and code behind again? any architectural reason?
2 Replies
Angius
Angius12mo ago
To be clear, Razor Pages still use .cshtml files and Razor syntax, just like MVC with views The reason is that it's all sorted much more nicely Instead of
|— Views
| \— Index.cshtml
|— Models
| \— IndexModel.cs
|— Controllers
| \— IndexController.cs
|— Views
| \— Index.cshtml
|— Models
| \— IndexModel.cs
|— Controllers
| \— IndexController.cs
you have a nice and clear
|— Pages
| \— Index.cshtml.cs
| \— Index.cshtml
|— Pages
| \— Index.cshtml.cs
| \— Index.cshtml
No need to jump through three (at least) different folders, you have everything in one place The model and the controller are also one and the same, basically Which, sure, limits what you can do somewhat (can't return different views from the same handler, for example) but makes other things much easier Instead of passing around objects, you set and get properties And that the model is coupled to the handlers? Does it really matter, considering models shouldn't be shared between different views?
Shiv
ShivOP12mo ago
ok understood @ZZZZZZZZZZZZZZZZZZZZZZZZZ thank you for clarifying
Want results from more Discord servers?
Add your server