Razor Pages vs server-side Blazor

前端 未结 4 1254
感情败类
感情败类 2021-02-07 20:54

Razor Pages is used for server side web applications, just like in the good old days.

Blazor is aiming to provide an alternative to popular JavaScript frameworks (like

4条回答
  •  后悔当初
    2021-02-07 21:00

    First off, it should be mentioned here that the Component Model of Blazor Server App and Blazor WebAssembly App is one and the same. The only difference is their mode of executions. Blazor Server Apps, also known as server-side Blazor Apps are executed on the server, and the Html content yielded from such execution after, say, a user had clicked a button element, is send to the client (perhaps a browser) over a SignalR connection. Blazor WebAssembly Apps, also known as client-side Blazor Apps, on the other hand, are executed on the user's browser; that is C# code is running on the browser within a process at the end of which Html content is output and rendered in the browser.

    But what is the difference between Razor Pages and Razor components?

    Razor Components is the Component Model used in both mode of executions of Blazor. A component is a unit of code that usually derives from the ComponentBase class. It may contain two parts: view part which is made of Html markup mixed with Razor syntax, and code part which is C# code. A component can be a child component of another component, but it can be a Page Component; that is a component which, when rendered, constitutes a whole Html Document.

    Razor Pages is a web framework, just like the MVC framework. When you use Razor Pages, you create pages that employ Razor syntax and C#, just like Blazor, which explains why they seem so similar, at first glance. However, Razor Pages are created on the server only, and the Html Content is output (rendered) and pushed to users' browser. Their architecture is different, and you need to learn a range of classes in order to program in either of them. To sum up, the only similarity is the employment of the Razor syntax and C# . Language is the source of misunderstanding, and more than ever, in the world of programming, it is exemplified by the naming of Blazor (naming changes occurred several times) and unwittingly identifying it with Razor Pages. Adding to this the fact that you can embed Razor Components in Razor Pages seems to be the source of further confusion.

提交回复
热议问题