Upgrading view engine to Razor - asp.net-mvc

I wan't to upgrade my MVC.Net site to 3.0 and also upgrade my asp.net view engine to the Razor.
I have seen that e.g. master pages look a bit different, so are there any tutorials on how to do a switch from asp.net to Razor?
Also how can I update the view engine for an existing site?

I'd also suggest reading the blog posts by ScottGu as they're the best documentation that we've got for Razor.
I can suggest you try this tool for converting the bulk of the views (at least the simple ones):
https://github.com/telerik/razor-converter
But don't get me wrong - the conversion still requires human input and lots of it. Detailed knowledge of the Razor conventions is very much important.
Good luck!

Scott Gu has a good series of blog posts about how Razor layouts work.

Related

Official "How to" for MVC Editor/Display Templates?

I have been using MVC Editor & Display Templates for a while, but have come to realize that there seems to be very little official documentation on MVC Editor/Display Templates (Html.EditorFor() and Html.DisplayFor()). I found the basic MSDN documentation just showing the technical details (which on their own, are not very helpful), but I'm looking more for an official how-to, sort of like this example.
Are Editor/Display Templates more of an afterthought, and not really widely enough used to justify more in-depth official documentation?
Or, am I blind, and what I'm looking for exists, I just haven't found it yet?
Official documentation? Don't know any off hand, but I know there are a ton of examples. In particular, I like Phil Haack's discussion on model binding to lists. It includes an example for an editor template in a pretty complicated example. There's source code there, too.
Since he's co-authored every MVC Wrox book, I consider him a pretty definitive source:
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx
Here's another blog post (non-official) in a similar vein:
http://blogs.msdn.com/b/stuartleeks/archive/2010/03/30/collections-and-asp-net-mvc-templated-helpers-displayfor-editorfor.aspx
best article that I have found for it is:
http://www.growingwiththeweb.com/2012/12/aspnet-mvc-display-and-editor-templates.html
It explains how to create DisplayFor and EditorFor templates really well.
ASP.NET MVC have a lot of materials on http://www.asp.net/mvc with different examples. EditorTemplates and DisplayTemplates is spetial folders for models (like here Quick Tips About ASP.NET MVC – Editor Templates) and you asking about html helpers, not templates.

MVC 3 with Razor best practices

I am looking for best practices for using Razor with MVC 3. Now what I am hoping for is some type of article, not just a list of your professed best practices, but if you have any feel free to post them.
Why is this SO worthy? It seems hard to find info on how to best use Razor with MVC views. I know about the typical MVC best practices, I am looking for Razor specific ones. Those who use Razor know that its more than a token replacer. I want to know more about how you setup the site templates using Razor.
Like I said, I am looking for a good resource on the subject.
have you ever heard of Nerddinner.com? that website has been created with ASP.NET MVC an it is open source on codeplex.
Here is the release that has razor and MVC3 version of it;
http://nerddinner.codeplex.com/SourceControl/changeset/changes/55257
You could download the source code and play with it.
Edit :
Also have a look at below blog posts;
ASP.NET MVC 3: Layouts and Sections with Razor
ASP.NET MVC 3: Implicit and Explicit code nuggets with Razor
Deployment of ASP.Net MVC 3 RC 2 Application on a Shared Hosting Environment Without Begging The Hosting Company
ASP.NET MVC 3: Layouts with Razor
Razor Releated posts on Phil Haacked's Blog
Razor syntax is not all that you are looking for, you want the best patterns and practices with using MVC 3 as well. It is a shame there are Zero books out on MVC3, only web references with vary from small to large degree. At this point you must use stackoverflow and constantly use google and set a date range to search past month or so. Also, setup a google "alert" on mvc 3 razor etc..
I find that pluralsight examples, nerddinner, Silk (MileageStats), MvcMusicStore, ProDinner, and several others to be "useful" yet not one is (or can be) the best practices in every area. Everyone tries the "happy path" but many of the example veer from this. Many examples are doing various IOC containers. Some use Unity others Structuremap, others Ninject. Depending on skill level and existing knowledge, it can be overwhelming.
Personally I'm on a new project with vs 2010 / mvc3 with Oracle 9... Thus MOST of the examples are not terribly helpful as the database integration with EntityFramework use datacontext / IQueryable is great and all, but with Oracle EF in beta, and sprocs not even working with Oracle 9 with EF (per trying , and email responses from Oracle trainers etc..) I end up having to go old school and retrofit ADO.NET and convert to List ... and use IEnumerable. Thus many of the things stubbed out for easy use in the models/controllers/views in the demo projects are half in vain for me with my environment with Oracle.
Well... I use MVC 2 and work and MVC 3 at home and I really haven't found too many differences in terms of best practices for the Razor syntax. I generally just read ScottGu's or Phil Haack's blogs if I want to read about ways to use the features of Razor. Not sure if that helps you any but I am drawing a blank.
Please check below link for example with good presentation.
http://dotnetautor.de/blog/content/binary/Windows-Live-Writer/32ee537b2c00_E16A/MVC3.pdf

ASP.Net MVC - Webform View Engine Performance

I heard viewengines like Razor or NHaml is giving much performance than WebForm View engine. Can someone advice me if this is true and which will be the best view engine
If changing the view engine significantly impacts performance, there is something wrong with your design. Views are for simple display of properties in the model - nothing in there would be taking nearly as long as things like database access which happen in the controller. An order of magnitude improvement in the view rendering probably wouldn't be a noticeable difference in the time for the whole request.
MVC 3 may perform better than MVC 2, but that's just a matter of using the latest version which has improvements in all parts of the system. View engine choice is about your preferred syntax, not performance.
MVC 3.0 still in development, so in final release performance will be even much better i guess.
Here is some Razor tests ASP.NET MVC 3 Razor performance and asp.net mvc3 razor documentation? and of cause http://haacked.com/
I would expect that the WebForms view engine and Razor view engine to yield similar performance as they are built on similar principles. Both work by parsing a file (ASPX vs CSHTML) to generate a codedom which itself is used to generate a compiled class. The big difference comes in the optimisations built into the parsers/code generators used by each.
Don't know about the exact performance between Webforms and MVC. Been working with webforms for a while and i'm currently working with MVC2 and experimenting with MVC3's Razor View Engine.
Though MVC3 is still in the RC2 state the performance is pretty good but i guess it still have to be tweaked before the final release .Rumours are that the performance should be equal to MVC2.
If you ask me i think that MVC2 and the new Razor Engine aren't any slower than Webforms applications. But personally i find the code easier maintainable with MVC, that's for me the biggest reason i switched from Webforms to MVC. Don't know anything about NHaml, but would personally choose Razor, works great! It's easy to use, understandable and gives good and clean code.
EDIT:
Read Scott Guthries blogs about the MVC3 RC2 candidate. He talks about performance. See this link.
Another topic on SO already exists about performance. Read it here
It always interessting to follow the blog pages of Scott Guthrie and Phil Haacked. Both work at Microsoft and regular post about MVC3.

Spark T4 templates for ASP.NET MVC

I was just curious if any Spark T4 templates already exist that match/are similar to the out of the box web forms view templates (create, edit, details, etc...). My Google skills didn't lead me to any results.
I've translated the mvc2 templates to spark, feel free to copy:
http://guiftp.free.fr/SparkViewTemplates.rar
T4MVC should work fine with Spark. Here is a related forum thread. That being said, I'm not clear from your initial post that T4MVC is the kind of thing you're looking for.
I meant this part of comment ! if it helps...
# re: T4MVC 2.5.01: added support for Html.RenderAction and Html.Action
#spark_guy: I haven't played extensively with the Spark view engine, but I think that T4MVC should work with it just as well as it works with the aspx view engine. If you hit specific issues, please let me know.
YOu can find all the T4MVC posts at http://blogs.msdn.com/davidebb/archive/tags/T4MVC/, though ideally there would be a single posts that describes it all in one place (I'll try to do this). Note that if you download T4MVC, the readme has good 'getting started' info that tells you what it's all about.

Best sites for ASP.NET MVC RC Refresh Documentation

I am trying to figure out how to use ASP.NET MVC and it seems the only way to learn it is through reading blog posts. Scott Gu and Phil Haak are the two that come to mind. The problem I am running into is that alot of the documentation they write is relevant at the time and doesn't work in the latest versions.
Is there a place that has the documentation for RC only? What are the best places to look for documentation on MVC RC?
Maybe this helps: http://stephenwalther.com/blog/archive/2009/01/27/a-guide-to-learning-asp.net-mvc-release-candidate-1.aspx

Resources