0

I'm new to MVC, There is one MVC application on which I'm working which used aspx engine (views are created in aspx). Now there is a requirement of migrating the GUI of application and I've read on that razor provides benefits over aspx engine. So, which is better to implement.

But, I'm more concerned about the performance of the application and its maintainability. So, could anyone please let me know which one satisfies above requirement?

Geeky Ninja
  • 6,002
  • 8
  • 41
  • 54
  • Maybe [this](http://blogs.msdn.com/b/marcinon/archive/2011/01/17/mvc-3-performance.aspx) can help you on the performance side. – von v. Apr 22 '14 at 08:11

4 Answers4

1

You can mix Razor and ASPX in one project, BUT you can not reuse the Master page from ASPX as a Razor layout page (at least not without some tricks AFAIK).

So depending on the size of the already existing application and the amount of additions it may makes sense to convert the existing pages to Razor or continue to use ASPX.

For maintainability reasons I personally would NOT mix the two in the same application.

UPDATE after comment:
1000 screens is definitely NOT mid-size anymore IMO, BUT if you are not using layouts and/or Master pages your may are really best of "mixing them" to benefit from the better/easier syntax and perfromance for new pages, but no requirement to adapt the old ones righ away. Old pages can be adaped one by one, when they are changed for other reasons...
Your team shouldn't have a big problem getting into Razor, as it is very near to "normal programming" and you only need to learn very few syntax "specialities"...

Christoph Fink
  • 22,727
  • 9
  • 68
  • 113
  • @@chrfin my application is of mid size , it has somewhere around ~1000 screens. And in my application I don't have any master page, so converting it to layout page will not be applicable. I was thinking of using the ASPX as it will reduce the work to migrate the application as well as maintainability will be there as team is already aware of ASPX pages. But, I'm more confused regarding the performance. – Geeky Ninja Apr 22 '14 at 08:00
1

I would say that the advantages of Razor are as follows:

  • Concise syntax, which is very similar to the way you write regular C# code (check out the following recent blog post by Phil Haack comparing Asxp with Razor syntax: http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx)

  • Automatic HTML encoding of output (which helps protect you from html injection attacks)

  • Built in (though not 100%) validation of your markup which helps you avoid unbalanced tags

The page-related concepts also map easily from what you have in ASPX

  • As you can see inline code is still allowed
  • Sections (which can be optional) are equivalent to content placeholders
  • Layout pages instead of Master pages
  • The concepts of full and partial views are the same
  • @functions { ... } blocks instead of ...

In addition Razor has a number of useful concepts that I would say are better than what is available in ASPX:

  • @helper functions for really easy creation of functions that emit markup
  • @model keyword for specifying your view's model type without having to write a <%@ Page ... directive with the full class name

As per my advice Razor is better option.

Ajit Kumar
  • 534
  • 3
  • 8
1

Have you read ScottGu's Blog. It's not specifically about performance but you'll be conviced why to use Razor.

Compact, Expressive, and Fluid: Razor minimizes the number of characters and keystrokes required in a file, and enables a fast, fluid coding workflow. Unlike most template syntaxes, you do not need to interrupt your coding to explicitly denote server blocks within your HTML. The parser is smart enough to infer this from your code. This enables a really compact and expressive syntax which is clean, fast and fun to type.

This topic has been discussed already so many time.

ASP.NET MVC 3 Razor performance

ASP.NET MVC View Engine Comparison

MVC 3 ASPX VS RAZOR View Engine

Community
  • 1
  • 1
Ashwini Verma
  • 7,477
  • 6
  • 36
  • 56
0

It mostly depends on personal preference, but Razor should have a great performance because it is fully compiled. Also the maintainability is in my opinion better, because of better readability and a syntax which isn't only familiar to ASP.NET developers. For a complete discussion have a look at this blog post.

Horizon_Net
  • 5,959
  • 4
  • 31
  • 34
  • @@Horizon_Net could you please brief me how razor can increase the performance? – Geeky Ninja Apr 22 '14 at 08:02
  • Like said above Razor is compiled which provides a better performance. Have a look at the comments of the blog post I mentioned above. There's a small discussion about performance. – Horizon_Net Apr 22 '14 at 08:04
  • What do you mean by "Razor... is fully compiled"? Are you saying "it can be" by using a tool or that "it is by default"? When you say compile I'm thinking the razor files are included as assemblies (DLL) in a project. Can you clarify on this? – von v. Apr 22 '14 at 08:08
  • When hitting a Razor page the first time (after changing the file) it is converted to a class and gets compiled. This compiled version is then used for every further request until the next change... – Christoph Fink Apr 22 '14 at 08:18
  • It is compiled by default at runtime, but you can change this behavior to compile-time. From your description this should be something you should consider. For more information take a look at [this post](http://stacktoheap.com/blog/2013/01/19/precompiling-razor-views-in-asp-dot-net-mvc-3/). – Horizon_Net Apr 22 '14 at 08:22
  • In the blog post you linked to, the guy is using a nuget package and it means it's NOT by default. By default means when I install VS, creates a project, builds it then all razor files are converted to DLLs. Maybe we are using different terminologies. Again, when I hear (read) compiled I'm always thinking that CSHTMLs are converted to DLLs. Maybe that's not what you were suggesting? – von v. Apr 22 '14 at 08:29
  • Just read the comment of @chrfin carefully. He says the same thing I say. The link I posted in my last comment is about how you can change the default behavior of Razor, that means using a third party tool. The default behavior is that it is compiled at runtime in the same way already mentioned above. – Horizon_Net Apr 22 '14 at 08:34