Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

MVC 3 - Razor View Engine

0 (0 Likes / 0 Dislikes)
  • Embed Video

  • Embed normal player Copy to Clipboard
  • Embed a smaller player Copy to Clipboard
  • Advanced Embedding Options
  • Embed Video With Transcription

  • Embed with transcription beside video Copy to Clipboard
  • Embed with transcription below video Copy to Clipboard
  • Embed transcript

  • Embed transcript in:
    Copy to Clipboard
  • Invite a user to Dotsub
[ASP.net] [www.ASP.net] [John Galloway] Hi, this is John Galloway with Microsoft, and this is an ASP.NET MVC 3 Quick Hit Video. In this video we will be looking at the basics of the razor view engine. We'll look at some more advanced features in some follow along quick hit videos. You'll first encounter the razor view engine when you create a new ASP.net MVC 3 web application. When you hit OK, you'll hit a secondary dialogue that offers you a choice of view engine. This is new in MVC 3. Prior to that, your only real built in choice was the ASPX or web forms view engine. So when I selct OK, that's going to set the default for this project to be the razor view engine. Just by setting the default for the project doesn't mean that I've made a project-wide choice, however. Every time I create a view I have the option of creating either a web forms or a razor view. So I can create a web forms view easily by just changing this and clicking Add. So you'll see here in the same project I have a web forms view page. One of the main goals of the razor view engine is to minimize the friction of code transitions. So if we look at a web forms view where we want to iterate through something and write out an unordered list, you can see that there are several transitions when we switch into C-sharp mode, when we switch back into html, then when we write out some information, and when we switch back into C-sharp mode just to close out. There's a big contrast here when we look at the same thing in a razor view page. You can see that we really only have to do 1 transition here where we explicitly say, "Yes, we're moving into C-sharp mode." And when we write something out, we just use this at sign, to say either transition or just write something out. It's pretty smart too, because we can still put in something like an e-mail address, and it understands that this is an e-mal address and does not transition into code mode. An important thing to realize here is that this is not a new language, it's not really a dramatic new syntax. All we're doing is we're using this at sign to transition into code mode. And based on whether we're using cshtml or vbhtml, we just write C-sharp or vb code at that point. So to see an example of this, I've created a very simple class called Cowboy, that has 2 properties, Name and Horse. Then in my home controller I've created a new action result for Cowboys. And I'm just returning a simple list that's hard coded here. So when I add a strongly typed view, of Cowboy, using the list template, you can see that the actual code that's writing out these values is extremely terse. Instead of the longer page declaration, here our model declaration is very short. And actually writing out these values just flows in with the html. One other thing to notice is that our html helpers are also very short and terse. So we just have @html. And of course we've got all of the intellisense that we'd expect. This concludes our quick view of the razor view engine. We'll be taking a look at some more advanced features in some follow on episodes. [www.ASP.net]

Video Details

Duration: 3 minutes and 36 seconds
Country: United States
Language: English
License: All rights reserved
Genre: None
Views: 6
Posted by: neudesicasp on Sep 18, 2013

In this video you will learn the basics of the new Razor view engine included in ASP.NET MVC 3.

Caption and Translate

    Sign In/Register for Dotsub to translate this video.