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

ASP.NET MVC 4

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
[Microsoft ASP.net] [www.ASP.net] [Visual Studio 2012 & One ASP.NET - Scott Hanselman, Principal Community Architect, Microsoft Corporation] Hi, this is Scott Hanselman, and I wanted to take a moment to talk to you about some of the new features in Visual Studio 2012— in this video, ASP.NET MVC 4. [ASP.NET MVC 4 - Scott Hanselman, Principal Program Manager, Microsoft Corporation] This is part of the overall ASP.NET ecosystem. ASP.NET MVC is our Model-View-Controller pattern. By default you get a number of cool features with MVC. Let's switch over to Visual Studio and I'll show you a few. I'll say New Project. There's a completely empty ASP.NET MVC 4 project, a basic one with just the scaffolding to get you started, an Internet Application, an Intranet Application that uses Windows Authentication, and a Mobile Application that uses jQuery Mobile to jump-start your mobile development, and then ASP.NET Web API that I'll cover in another video is also included in ASP.NET MVC 4. Take a look at the Internet Application and run it by default. All of these templates are HTML5 by default now, and notice that they include responsive design. This default template resizes and changes for small devices. So you get a little bit of mobile support there as well. Let's go and create a small model. Add, Class. We'll make a Person. Here's a Person, and we'll say that a Person has an ID and they have a First name and they have a LastName and they have a Birthday. I haven't described the database here. I'm going to be using Entity Framework Code First, so I'm describing a database but I'm starting with code first. Now I'm going to right click and say Add, Controller. We're going to add an MVC controller and I'll call it a PersonController. We have a number of templates to choose from. I can scaffold out lots of different things. In this case we're going to scaffold out Person, make a new data context called the PersonContext, and we're going to use the Razor view engine for our view. So I'll hit Add, and this is going to start scaffolding out that. Watch the right side of the screen. We just got a PersonController with a Person data context, Details, Create, Read, Update, Delete for Person. We got a Person database context for the Entity Framework that will by default use LocalDB but could use SQL Azure or anything else. We've also got a Person Views—Create, Delete. Let's run that and see what we've got in just a few seconds. Type in Person, and the scaffolding created an Index page where I can go and say Create. I can edit, delete, view details. It took very little time to get a nice little simple site going, automatically created a database for me. I'll look in the Server Explorer and you can see there's People. The data types were taken care of. You can also make a quick change. Let's say we want to make sure first name and last name are required rather than optional. Come down into the console here and enable migrations. We're going to enable database migrations for our MVC application. All right. This is going to allow me to make a change to Person and change the database. I want to change First name to Required, LastName to Required, and I'll also make a maximum length. Let's just be silly and say that last names can only be 10 long. I've made that change here in my model. Let's go and add a migration, "added required". Here we see First name and LastName are no longer nullable and LastName has a maximum length of 10. Now we'll go and update the database... applying those migrations. Those migrations are located here in the Migrations folder. I'll run the application. Go to Person. I'm going to make a new person. First name, LastName required. Let's make a person with a super long la— See? Just as I'm typing superlonglastname, it says the field must be a string with a maximum length of 10. So we've got the information about our model stored on the model in one place and it's propagating its way through the database, through the JavaScript that handles the unobtrusive validation. I was able to keep the application dry. Don't repeat yourself. Another nice feature of ASP.NET MVC 4 is mobile support. We've added mobile support. Here's an application. This is the desktop version of the application. I'll go and add a mobile layout. I'm going to take my Layout file and say Mobile right here. Then on the main desktop page I'm going to add what's called a ViewSwitcher. A ViewSwitcher can ask questions like, "Is this a mobile browser?" and if it is, show a link that says, "Switch to mobile," or "Switch to desktop." In this case it's only going to show up on mobile devices. I'm going to comment that out so my desktop people can insist on the mobile version of the site. Here it says Displaying desktop view. I'll click on Mobile. Now I've got a mobile version of my page. This is usually in the jQuery Mobile libraries. This information here is the same, though. We're changing the layout but the middle part is the same. Let's add a separate page for that. Notice that just by naming it .Mobile, the URL stays the same but the page that's rendered is different. Here's our mobile page. Hit F5. Now we've got a nice mobile menu. This is appropriate for desktop browsers, and here's a more appropriate view for a mobile browser. This is made possible by the mobile support in ASP.NET MVC. I can have not just .Mobile with these display modes but also things like iPhone specific or Windows Phone specific. Different views can have different layouts, all maintaining the same URL structure. Mobile support is built in to ASP.NET MVC as well. That's just a few of the features that are new in ASP.NET MVC 4. I hope you continue to explore this video series and check out some of the other new features in Visual Studio 2012 and ASP.NET 4.5. [Microsoft ASP.net] [www.ASP.net]

Video Details

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

ASP.NET MVC 4

Caption and Translate

    Sign In/Register for Dotsub to translate this video.