Showing posts with label When ASP.NET MVC. Show all posts
Showing posts with label When ASP.NET MVC. Show all posts

Tuesday, July 27, 2010

Building first ASP.NET MVC Application

logo_300
Hello Guys,
Today We are gonna start with the Asp.Net Mvc development..
I Hope you people are also eager to learn it.....so let's begin with the work...
before starting with the development make sure that you have clear understanding of Asp.Net MVC basic and When to choose Asp.Net MVC ?

What You Should Know Before Developing an Asp.Net MVC Application


We make few assumptions about your technical background. We assume that you know the C# .NET programming language — all the code samples will be in c# also assume that you know basic HTML. ASP.NET MVC uses many advanced features of the C# .NET language.

What Software Do You Need?

You can download all the software that you need to build ASP.NET MVC applications from here. You need to install three software components:
1. Microsoft .NET Framework 3.5 Service Pack 1 The Microsoft .NET framework includes the Microsoft ASP.NET framework.
2. Microsoft ASP.NET MVC 1.0—The actual ASP.NET MVC framework that runs on top of the ASP.NET framework.
3. Microsoft Visual Web Developer 2008 Service Pack 1 or Microsoft Visual Studio

Understanding the Sample ASP. NET MVC Application


A good way to get a firmer grasp on the three logical parts of an MVC application is to take a look at the sample application that is created automatically when you create a new ASP.NET MVC project with Visual Studio.
Follow these steps :
1. Launch Visual Studio.
2. Select the menu option File, New Project.
3. In the New Project dialog, select your programming language as C#  and select the ASP.NET MVC Web Application template. Give your project the name MyFirstMvcApp and click the OK button.
Note : I am using VS 2010 so its having latest release of MVC that is MVC 2 that is why it is showing "ASP.NET MVC 2 Web Application" otherwise You will have simple "ASP.NET MVC Web Application" in VS 2008. Make sure that you select the .NET Framework 3.5 as the target framework.
4.Immediately after you click the OK button to create a new ASP.NET MVC project, you see the Create Unit Test Project dialog shown in the below snap.Leave the default option selected—Yes, Create a Unit Test Project—and click the OK button.
5. Visual Studio creates the default files for a new ASP.NET MVC project. After all the files are created, the Solution Explorer window should contain the files shown in the below image :
The Solution Explorer window in above Figure contains two separate projects: the ASP.NET MVC project and the Test project. The Test project contains all the unit tests for your application.

ASP.NET MVC Folder Conventions


The ASP.NET MVC framework emphasizes convention over configuration. There are standard locations for each type of file in an ASP.NET MVC project. The ASP.NET MVC application project contains the following folders:
  • App_Data—Contains database files. For example, the App_Data folder might contain a local instance of a SQL Server Express database.
  • Content—Contains static content such as images and Cascading Style Sheet files.
  • Controllers—Contains ASP.NET MVC controller classes.
  • Models—Contains ASP.NET MVC model classes.
  • Scripts—Contains JavaScript files including the ASP.NET AJAX Library and jQuery.
  • Views—Contains ASP.NET MVC views.
When building an ASP.NET MVC application, you should place controllers only in the Controllers folder, JavaScript scripts only in the Scripts folder, ASP.NET MVC views only in the Views folder, and so on. By following these conventions, your application is more easily maintained, and it can be more easily understood by others.

Running the Sample ASP.NET MVC Application


When you create a new ASP.NET MVC application, you get a simple sample application. You can run this sample application by selecting the menu option Debug, Start Debugging (or press the F5 key).
The first time that you run a new ASP.NET MVC application in Visual Studio, you receive a dialog asking if you want to enable debugging. Simply click the OK button.
When you run the application, your browser opens with the page in Figure below :

This sample application is implemented with one ASP.NET MVC controller and two ASP.NET MVC views. The sample application does not contain any business or data access logic, so it does not contain any ASP.NET MVC model classes.
The controller is located in the Controllers folder:
\Controllers\HomeController.cs
If you open the HomeController in the Code Editor window, you will see the code as below :
Controllers\HomeController.cs


There are two methods named Index( ) and About() . Methods exposed by a controller are called actions. Both the Index() and About() actions return a view.
When you first run the sample application, the Index() action is invoked and this action returns the Index view. If you click the About tab, the About( ) action is invoked and this action returns the About view.
The two views can be found in the Views folder at the following location:
\Views\Home\About.aspx
\Views\Home\Index.aspx
The content of the Index view is contained as below :

Notice that a view consists mostly of standard HTML content. For example, the view contains standard <h2> and <p> tags. A view generates a page that is sent to the browser.
That's it...!!!
You learned how the ASP.NET MVC framework implements the Model View Controller pattern and how ASP.NET MVC enables you to perform pattern-based software development.
So ? how was the first ride to ASP.NET MVC Sample Application ?? :-)  I Hope it would be great... :-)
Hope this helps...

When to Choose an MVC Application ?

Inno design
Hello Guys,
After reading the first post on ASP.NET MVC , You may have a question in your mind that when to use ASP.NET MVC..so here is the answer of it..

Deciding When to Create an MVC Application

You must consider carefully whether to implement a Web application by using either the ASP.NET MVC framework or the ASP.NET Web Forms model. The MVC framework does not replace the Web Forms model; you can use either framework for Web applications. (If you have existing Web Forms-based applications, these continue to work exactly as they always have.)

Before you decide to use the MVC framework or the Web Forms model for a specific Web site, Go through the advantages of each approach.

Advantages of an MVC-Based Web Application


The ASP.NET MVC framework offers the following advantages:
  • It makes it easier to manage complexity by dividing an application into the model, the view, and the controller.
  • It does not use view state or server-based forms. This makes the MVC framework ideal for developers who want full control over the behavior of an application.
  • It uses a Front Controller pattern that processes Web application requests through a single controller. This enables you to design an application that supports a rich routing infrastructure. For more information.
  • It provides better support for test-driven development (TDD).
  • It works well for Web applications that are supported by large teams of developers and Web designers who need a high degree of control over the application behavior.

Advantages of a Web Forms-Based Web Application


The Web Forms-based framework offers the following advantages:
  • It supports an event model that preserves state over HTTP, which benefits line-of-business Web application development. The Web Forms-based application provides dozens of events that are supported in hundreds of server controls.
  • It uses a Page Controller pattern that adds functionality to individual pages.
  • It uses view state or server-based forms, which can make managing state information easier.
  • It works well for small teams of Web developers and designers who want to take advantage of the large number of components available for rapid application development.
  • In general, it is less complex for application development, because the components are tightly integrated and usually require less code than the MVC model.

Features of the ASP.NET MVC Framework

The ASP.NET MVC framework provides the following features:
  • Views without code-behind that is all other view engines works with code-behind views whereas here we will just have separate .aspx file for view.
  • Separation of application tasks that is input logic, business logic, UI logic, testability, and test-driven development (TDD) - all are defined differently so its good and no pore complex.
  • HtmlHelpers now expose the model of the view - this is strictly related to the new feature. Since you cannot create view-specific helpers anymore, we needed a way to supply the model of the view to HtmlHelpers.
  • UI Scaffolding - when you create a view, now you can ask Visual Studio to create the HTML of the UI to edit/create/delete/list/show the model supplied to the view  that we will show you in the example soon.
  • Powerful URL-mapping is component that lets you build applications that have comprehensible and searchable URLs. URLs do not have to include file-name extensions, and are designed to support URL naming patterns that work well for search engine optimization (SEO).
  • Support for using the markup in existing ASP.NET page (.aspx files), user control (.ascx files), and master page (.master files) markup files as view templates. You can use existing ASP.NET features with the ASP.NET MVC framework, such as nested master pages, in-line expressions (<%= %>), declarative server controls, templates, data-binding, localization, and so on.
  • Support for existing ASP.NET features - ASP.NET MVC lets you use features such as forms authentication and Windows authentication, URL authorization, membership and roles, output and data caching, session and profile state management, health monitoring, the configuration system, and the provider architecture.
  • Lots of new helper functions, utilities, and API enhancements
So this is all about When to use ASP.NET MVC Framework. Just Go through all the points and matched with your  proposed system's criteria , you will come to know that which will be more beneficial to implement.Hope you would have got the basic understandings of ASP.NET MVC now.
We will move on to the tutorials from the next post.
Hope this Helps...