Learning asp.net mvc is really easy which we will realize during our articles. We will start from the very beginning to create a hello world application an application using insert, update, delete features and then try to give the option to sell them by using shopping cart at the end of the article.
If you already know the asp.net then it's good and if not then it's best, because in MVC, we don't have any server side controls so those who already know asp.net need to forget about server side controls as well as code behind of the asp.net page.
Model - M in MVC:
It contains all application logic (business logic, validation logic, and data access logic), except pure view and controller logic. It is not necessary to use business and data access login in model even you can use loosely coupled model layer. There are some ORM libraries like Hibernate (Java), NHibernate (.NET), Doctrine (PHP) or ActiveRecord-Rails (Ruby) that really can generate all actual SQL statements for you. In our example we will use Entity Framework database first so we will use it into model itself.
View - V in MVC:
A view is a (visual) representation of its model data. It's a simple HTML file like our asp.net page html code which uses razor view to render the elements and CSS to design the look and feel of the page.
Controller - C in MVC:
A controller is the link between a user and the system. The controller responds to actions by the user taken the in the view and responds. You put validation here and select the appropriate view if the validation fails or succeeds (error page, message box, whatever). MVC requires the name of all controllers to end with "Controller".
MVC together:
When a user type some URL or click any button on the page, it check the controller and then action, once found, it use the model to get the date and send it to view to represent to the user. Let's say the user types http://www.google.com/analytic/detail, the application will first check for the controller analytic, once found check for the action detail, once this action found in controller try to get the data for the view and send to view to represent for the user.
Now we know what is MVC. We will create project and will try to understand the application structure by looking folder by folder from top to bottom. So what we are waiting, let's start now, I have Visual Studio 2013, if you are using different version then might be options will be different.
Now our default project is created, we will explore it's different folders and will try to understand them, before that run the application and check what we already have in our application created by visual studio. It have home, about, contact, login and register page, every page is working smooth and a nice design with CSS. It is using bootstrap to design the application.
Open HomeController and add a message Hello World
public ActionResult Index()
{
ViewBag.Message = "Hello World";
return View();
}
Right click inside index action and select "Go To View" and add following line
<h3>@ViewBag.Message</h3>
Run the project and see it is showing on the page, it is way to pass the value from controller to view.
Please suggest us what you want to see
![]() |
Having 13+ years of experience in Microsoft Technologies (C#, ASP.Net, MVC and SQL Server). Worked with Metaoption LLC, for more than 9 years and still with the same company. Always ready to learn new technologies and tricks.
|
By Ali Adravi On 21 Feb, 15 Viewed: 1,529 |
MVC Searh page with pagination: It’s very easy to create a search page in asp.net but when I try to create the same in MVC I faced many problems, how to create model, how to keep searched values in search controls, pagination, I found myself nowhere, so start searching for some good examples but... By Ali Adravi On 25 Aug 2013 Viewed: 40,117
CRUD (Create, Retrieve, Update and Delete) in MVC. When we start to learn new language, first we try to run an application with “Hello World” and then CRUD functionality. So in this article we will see how to select records from database (with WebGrid, pagination and sort functionality), update a... By Ali Adravi On 17 Aug 2013 Viewed: 105,947
Sometimes we need a thanks page say we have user registration, change password, activate account functionality in our application then we need a thanks page after registering with our site, to say thanks for registering with us or showing confirmation that your password is successfully changed or... By Hamden On 30 Jun 2013 Viewed: 3,738
In MVC, autocomplete with jquery is the best way to pull data from database and render according to our requirements, so in this article we will use jquery to show the auto complete text box without any ajax controls. We need a method to get the data from database, a controller method to handle the... By Ali Adravi On 29 Jun 2013 Viewed: 6,997
Upload multiple files with model data in MVC is really very easy, when I started to test by uploading some files, I though it would be more complicated but it is really not. In my previous post [ASP.Net MVC file upload][1], I promised to post soon about how to upload multiple files. When I was... By Ali Adravi On 04 Jun 2013 Viewed: 25,493