开发者

Needing help to distinguish between WebMatrix, ASP.NET Web Pages and the Razor syntax

开发者 https://www.devze.com 2023-02-13 18:04 出处:网络
Much of the documentation for the new Razor view engine is in the context of WebMatrix and ASP.NET \"Web Pages\".Even in the MSDN library itself, the article that seems (to me) to be the root referenc

Much of the documentation for the new Razor view engine is in the context of WebMatrix and ASP.NET "Web Pages". Even in the MSDN library itself, the article that seems (to me) to be the root reference page for most of the Razor documentation (ASP.NET Web Pages with Razor Syntax) is inherently tied to ASP.NET Web Pages, and is under a branch in the documentation tree titled "Microsoft WebMatrix".

However I gather from other things that I have read, that Razor syntax is also available for ASP.NET MVC 3, which seems to have very little to do with ASP.NET Web Pages.

Now I am new to this whole area, and I am learning in WebMatrix at the moment, so please correct me if I get some of the details wrong, but I know that I am going to want to also start learning ASP.NET MVC in the near future, so making these distinctions will be important to that transition.

So I am looking for a definitive guide that will allow me to understand exactly which parts of what I am learning are part of the Razor syntax, and which are part of ASP.NET "Web Pages".

Also I need to clarify if there is any distinction between WebMatrix and ASP.NET Web Pages. I understand that WebMatrix is based on "Web Pages", but it is not clear if some of what I am learning 开发者_如何学Pythonis specifically a part of WebMatrix, or if (as I suspect) WebMatrix is just an IDE around "Web Pages", with nothing much added other that the UI.

Can anyone out there provide some clarity in these areas please?

(By the way, am I missing something (else), or is "Web Pages" the most confusing name they could possibly have come up with for this new system?)


Yes, ASP.NET WebPages is a confusing name. We tried but could not come up with anything better. Sorry :)

For a really good description of the various interaction between MVC, Razor, WebMatrix, and WebPages read David Ebbo's blog post How WebMatrix, Razor, ASP.NET Web Pages and MVC fit together.

The Razor syntax pretty much boils down to the @ symbol, a few keywords (such as @helper, @inherits, @section), and the smart parsing of a razor file to figure out the transitions between code and markup. Everything else is either standard C# code (the ifs and fors), markup, or libraries and utilities provided by the WebPages framework.

Now Razor and WebPages are not completely seperated and there are built in connections and conventions between the two that make everything work together. For example @section is a Razor keyword. The Razor parser converts it into code that calls the WebPages framework method DefineSection, so that later in a layout page you can call @RenderSection.

The usage of Razor in MVC depends on the WebPages framework. Specifically MVC extends the classes that represent a page from WebPages such that things like RenderSection still work in MVC. The only difference is that MVC has its own set of utilities and libraries that are designed for the MVC programming paradigm. For example, instead of calling the Href method from WebPages, you would call Url.Content in MVC.

A large number of functions from WebPages will continue to work in MVC, though there might be more mvc-ish methods that you might want to call instead.


To expand on marcind's explanation, Razor was developed for Web Pages. The MVC team thought it would also make a great View Engine. There is only one version of the Razor "syntax", which is why MVC3 depends on the WebPages dlls.

Oh, and I think the guys had run out of ideas when they named both "Web Pages" and "WebMatrix". I wonder if Amazon has seen a recent increase in orders for 8 year old Web Matrix books?

0

精彩评论

暂无评论...
验证码 换一张
取 消