I'm very new to MVC...I have quite a bit of knowledge with Silver-light and WPF and MVVM but little knowledge in regards to MVC. I'm following along the main tutorial on Microsoft's site http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-a-view. I believe I'm on article 3 of 9. Originally it told me to create my MVC Site as using the "View Engine" of "Razor". I chose to use "ASPX" instead of "Razor" as I thought I would have less third party dependencies.
When starting a new MVC Web Application is it best to use "Razor" as opposed to "ASPX". To be honest I have no idea of the difference. As stated I chose ASPX to avoid any extra third party dlls or code. If it is best to choose ASPX I'm a bit confused as to why the tutorials on MS's site are telling me to start with Razor.
Can anyone shed some light on to when I should use the "ASPX" view engine as opposed to the "Razor" view engine?
From the docs, "Razor Pages can make coding page-focused scenarios easier and more productive than using controllers and views." If your ASP.NET MVC app makes heavy use of views, you may want to consider migrating from actions and views to Razor Pages.
Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML. It's just that ASP.NET MVC has implemented a view engine that allows us to use Razor inside of an MVC application to produce HTML.
MVC is good for those web application which has lots of dynamic server pages, REST APIs and AJAX call. For basic web pages and simple user input forms, we should go for Razor pages. Razor pages are similar to ASP.Net web forms in the context of structure, except page extension.
You can add support for Pages to any ASP.NET Core MVC app by simply adding a Pages folder and adding Razor Pages files to this folder. Razor Pages use the folder structure as a convention for routing requests.
There is no difference regarding dependencies on 3rd party anything. ASPX is fine, but Razor is better, mostly because it stays out of your way.
You should read Scott Guthrie's blog post Introducing "Razor".
You basically replace the opening and closing tags <%
and %>
with an @
symbol, so far fewer keystrokes to do the same thing, i.e.
<%: Model.UserName %>
becomes
@Model.UserName
and
<% foreach (string name in nameList) { .. } %>
becomes
@foreach (string name in nameList) { .. }
There's a little more to it than that, but not much.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With