Placeholder Image

Subtitles section Play video

  • Hello everyone and welcome to Learn MVC step by step in 2 days

  • 2 days means 16 hours

  • yes you guessed it right 16 hours

  • so first thing you would ask me that some kind of scammer something

  • absolutely not this is not scam something this is the real thing

  • so next thing you would ask me that hmmm

  • so is it really possible to learn MVC in 16 hours

  • my answer is yes

  • absolutely yes and confidentially yes

  • okay

  • So before we start MVC right

  • we need to go and arrange our environment we need to go and ensure that we have the tools with us

  • the first thing what we should have with us is the ultimate edition

  • so this complete tutorial

  • this complete MVC tutorial is in MVC 5

  • but it holds too for MVC 4 as well

  • it holds too forMVC 3 as well

  • or MVC 2 also down the line right

  • So first thing is we need to go and get hold of this ultimate edition here you can see

  • I have the Visual Studio which is installed in my computer

  • so ensure that the first thing is you need to go online and serach for microsoft Visual Studio 2013 download

  • so once you go and search Visual Studio Ultimate edition on google right

  • you should actually go and land on to this page here

  • you can see I have highlighted the URL

  • In case you are not landed into that page

  • you can pause this video and you can copy that URL you can type that URL out and get to the right page

  • So now the next thing you would be asking me is that

  • why are you telling us to download this Ultimate Edition and why not free edition like XPlus Edition

  • or must be some kind of a downgraded edition like professional edition

  • This tutorial sincerely

  • very very sincerely aims at making you a true MVC professional

  • So I don't want to lose some features by downloading XPlus edition right

  • And second thing you know if worried about the price

  • watch on that screen watch my screen over there

  • it is clearly written free 90 days trial

  • So here you have 3 months with you 90 days is more than enough to learn any thing in the world right

  • so here you have 90 days before you a Visual Studio

  • and here I am promising you that I am going to teach you MVC in 2 days right

  • i.e. 16 hours so the remaining

  • whatever right 88 days is for you to go and create project if you wish right

  • So why go ahead and why

  • why should we download you know XPlus edition and lose some features

  • let's go ahead learn MVC like a true professional let's use Ultimate Edition

  • Once you have downloaded the ultimate edition and you have installed in you computer you should see on the screen what you see here

  • So click on file here click on new project

  • and click on this web menu over here

  • So once you click on the web menu here you can see a template here saying ASP.NET Web Application

  • You can also see one more sublink inside this web here Visual Studio 2012

  • So if you click on this you will see some template here and you can see the the MVC 4 template here as well

  • So the first question you know which would come to your mind is this two links over here

  • what is this web and what is this 2012 because if we click on this 2012 you are seeing MVC 4

  • if we click on this web you are not seeing anything right

  • So what are this two links?

  • Now this tutorial will be using MVC 5 for teaching you MVC

  • but whatever I teach in MVC 5 hold too for MVC 4 as well as MVC 3 and MVC 2 as well okay

  • Now in case you want to do MVC 4 then you need to click on Visual Studio 2012

  • and you need to use this template over here

  • and in case you want to do MVC 5 then you need to click on this web here and you need to actually go and create this project over here

  • Now this is a big difference between MVC 4 and MVC 5

  • In MVC 4 if you see you know you have different different templates here for example

  • You can see this is ASP.NET MVC 4 then we have ASP.NET Web forms and other things

  • very quickly before I move ahead with difference between MVC 4 and MVC 5

  • I want to clarify here something regarding ASP.NET

  • regarding MVC and regarding Web form

  • Lot of people think that ASP.NET is different and MVC is different

  • Absolutely wrong okay

  • First thing our base framework is .NET right

  • From .NET ASP.NET is created so again ASP.NET is a framework for web applications okay

  • From .NET we have various framework you know like

  • we have a windows framework

  • you know we have a web framework

  • So this ASP.NET is a web framework

  • and using ASP.NET microsoft has created web forms and it has created MVC

  • So don't think that MVC is different from ASP.NET

  • MVC uses ASP.NET internally

  • So recaping very quickly

  • So at the base we have our .NET Framework on that top ASP.NET is created for Web Applications

  • and from ASP.NET we have something called as web forms

  • whenever I say old ASP.NET I mean by ASP.NET web form

  • Web Forms has a behind code

  • so if you have ASPX it will have ASPX.cs right

  • So that is our old ASP.NET web forms

  • and this new architecture MVC 4 or MVC 5 whatever you think right is a separate thing

  • So we have web forms and MVC using ASP.NET internally and ASP.NET uses the .NET framework internally

  • So now if logically web forms and MVC belongs to ASP.NET framework then why should we have such kind of separate templates

  • And that's what they had improved in 2013

  • In 2013 they created only one template for everything

  • You can see here rather than having this templates you know separate manners if you click on web here

  • you can see now it is saying ASP.NET web application

  • and from there you can now go and make a choice say

  • okay now i want to create MVC now i want to create web form now i want to create API whatever it is right

  • So by creating this ASP.NET 1 you know it will avoid lot of confusion you know where people will thinking that ASP.NET is different and MVC is different right

  • So i am going to go and start from this template over here

  • if you wish in case you are into visual studio 2012

  • you can start from here the steps are almost same okay

  • but let me start with MVC 5 so that's a recent version and it will keep us you know upto date as well right

  • so let us say this is HelloWorld

  • so it's a first program HelloWorld and let say okay

  • Now you can see as i have said that it is one ASP.NET framework

  • you know all of these guys Web forms and MVC they have emerge from the ASP.NET framework

  • So you can see now this

  • second template here is telling me so what you want to do

  • do you want to use web forms

  • do you want to do coding in MVC

  • do you want to do coding in Web API

  • So from here you can see now you can go and make a choice of what things you want in your project

  • So at this moment we are learning MVC

  • So we have to go and select MVC over here

  • so you can see MVC is checked over there that is right

  • and what we will do is because this is our first HelloWorld program you know

  • let's not use any kind of authentication or security mechanism at this moment

  • we will talk about these options later on

  • So what I have done here is

  • i have clicked on this change authentication button here and I have said no authentication right

  • So you can see here I have selected here I have selected MVC

  • i have selected this check box and I am all set and i say just say okay over here

  • so you can see you know

  • the new project is created

  • you can also see the solution of the new project

  • In case you are not seeing the solution click on view here and click on solution explorer

  • So there you can see the complete solution of your MVC project

  • so now I am almost done with 5 minutes of the video

  • I have almost created a solution here but I have still not talked about what is MVC and why MVC

  • For now what we will do is we will talk about this why MVC later on

  • because if I start speaking about why MVC now right itself

  • it will lead to more confusion believe me that okay

  • so what we will do is let's complete 3 or 4 labs

  • and once you get hang of MVC then I will talk about why MVC

  • but for now let me talk about what is MVC

  • MVC stands for Model View Controller

  • MVC is nothing but it's a architectural pattern

  • where we divide our web application into 3 layers

  • one is the controller

  • the other one is the model and the last one is a view

  • So in other words every layer in MVC is assigned a unique responsibility

  • So the view is for look and feel and positioning

  • So the view is the something the

  • something the end user will actually see

  • The model supplies data and business logic

  • so the models are nothing but the classes like customer class you supplier class etc

  • and the model can intract with data access layer or some kind of services like wcf service or web service which gives data

  • and the controller who is actually the heart of MVC architecture

  • he is nothing but he is a coordinator between model and the view

  • so what happens is when a end users sends a request or action i will say rather

  • so here when we say request in MVC we term it as a action

  • so when a end users actually sends a action to MVC site it first hits the controller

  • and the controller depending on the action picks up the appropriate model and binds it with the view

  • and that result is send to the end user browser

  • so for example if a user send a action like

  • add customer now remember actions are normally verbs like add customer, update customer, go to home or whatever right

  • so when a end user actually sends a actions like add customer

  • this add customer action first comes to the controller

  • The controller then says okay let me search you know which is appropriate model for it

  • so must be the appropriate model is a customer model object

  • so he create objects of a customer model object and ties up with a view probably called customer.aspx

  • or in case you are using razor it can be customer.cshtml

  • so with this approach you know we end up assigning unique responsibility to each layer

  • so when we make changes in one layer the other layer is not affected

  • and this makes the software project more maintainable and more better in terms of architecture

  • so let us map our MVC architecture with the solution which we have just opened

  • so you can see here we have the controllers folder here

  • so all your controller code will go inside this folder

  • you can see we have a models folder here all your customer class your supplier class or whatever is your domain objects they will go into this

  • and then we have the views folder which will have the aspx or html or must be the cshtml UI

  • right

  • so at this moment don't worry about other folders I will come to them as we go ahead in the labs

  • so at this moment this where the controllers will go

  • this is where the models code will go

  • and this is where the views code will go

  • so let us move ahead and let's do lab1

  • Now before we start with Lab 1 let's go ahead and delete all these codes you know which have been inserted by the MVC templates

  • so that we can learn from scratch so you can see that I have deleted all the codes currently which is there in the controller folder

  • I want to go and delete all the folders which are there in my view folder so that we can start from scratch and I can teach you to exactly how things work

  • So you can see now all the codes have been deleted from the controllers folder

  • I have deleted the models folder did not have any code and even from the views folder there is no code here as well right

  • so everything clean everything nice

  • in the view folder there are some files but leave that files at this moment you know

  • they wont't affect us

  • you know while we are this first lab

  • So let us start with lap 1

  • displaying a simple Hello world in MVC

  • So whenever we start any programming language you know

  • as a tradition people always go and display hello words they get warmed up and then we can go ahead with more complex labs

  • So what we will do here is so let's create a very simple controller called as a home controller okay

  • And whenever end users comes he will say okay go to home so there will be actions in this home controller called as go to home

  • So he will send the action go to home and this go to home controller will go and display a page called as home.aspx must home.html

  • or home.cshtml some kind of a view

  • So at this moment we will not create any models let's keep it as simple as possible

  • because it's a first lab let's not get very heavy

  • So we will create a simple controller called as home

  • in that we will create action called as go to home and then that action will invoke a page called as home.html or home.aspx

  • so let us first right click on this controller here

  • So let's start from the start

  • so I want to and first add a controller here

  • add a contoller

  • so as soon as we have clicked on this add controller here you can see

  • he has popped up more templates for the controller

  • so for example you can see you know here is a controller with read and and write actions

  • So if I take this controller i will get some ready made code

  • Here is a controller which uses entity framework

  • you know in case you have not done entity framework please our videos of entity framework

  • you know where we will explain that what exactly the entity framework

  • but if I use this then there will be some ready made code

  • you know which will help me to connect to entity framework

  • so I will get some ready made code over here

  • but remember when we want to learn something

  • we should start from scratch

  • So you saw that how I deleted everything from the controllers folder

  • all the ready made code from the controllers folder

  • how I deleted all the views from the view folder right

  • So what we will do is let's select the first controller here

  • the empty controller

  • In other words in this controller in this template we will not get any codes

  • so we have to write from scratch right

  • So let me go and select this and I'll say add

  • So the next thing now what he tells us is that basically gives the name of a controller

  • And you can see

  • If you see this window over here

  • he has highlighted the controller name

  • but you can see that he has not highlighted this word controller

  • Remember that this word controller is a reserved word

  • don't even think about deleting this word

  • If you do that then you will end up into a mess

  • So Incase you want to name your controller as a home controller you should just say home and the word controller

  • In case you want to name the controller as a customer controller

  • you should say customer and the word controller