Resolved code section in blazor

SaeedP

Well-known member
Joined
Oct 21, 2020
Messages
97
Programming Experience
3-5
Hello,


Can the code that is written in Blazor in the code section be written in the controller?
Are the codes exactly the same?

thanks,
 
Solution
Unless you are very disciplined, Blazor almost encourages the old Win32/WinForms style of writing code where the business logic gets mixed in with the UI. This is almost equivalent to using MVC, but all the work happens in the View. The funny thing though is that most people's first foray in MVC leads to implementations where almost all the logic is in the Controller including micromanaging all aspects of the View. If you can write code that way, then you can then write Blazor code with almost everything in the Controller.

What you want to really do is have code in the Razor pages be focused on doing View specific stuff; the code in the Model focused in implementing the problem domain; and the Controller simply being a coordinator...
I've never used Blazor myself so I'm far from an expert but, from what I understand, the answer to your question is "sort of but not exactly". The point of Blazor is to use C# instead of JavaScript. That means that your Blazor code is effectively client-side code, where the controller is executed on the server. That said, Blazor code can be executed on either the client or the server. That seems to suggest that Blazor code could be something like what you would do in an async action. The two are not directly interchangeable though.
 
Unless you are very disciplined, Blazor almost encourages the old Win32/WinForms style of writing code where the business logic gets mixed in with the UI. This is almost equivalent to using MVC, but all the work happens in the View. The funny thing though is that most people's first foray in MVC leads to implementations where almost all the logic is in the Controller including micromanaging all aspects of the View. If you can write code that way, then you can then write Blazor code with almost everything in the Controller.

What you want to really do is have code in the Razor pages be focused on doing View specific stuff; the code in the Model focused in implementing the problem domain; and the Controller simply being a coordinator between the View and the Model.
 
Solution
Back
Top Bottom