I think it is useful to start by looking at what a popular application built using MVC looks like. You might be familiar with the Stack Overflow (SO) site.
SO is a popular programming web site in which users can ask programming questions to be answered by other users. Other users then answer the questions. These answers are then voted on by other users; those with the most votes (ideally the best ones!) move to the top of the answer list.
Let's take a look at SO now:
Open a browser, and go to http://www.stackoverflow.com.
Take a look around the site, paying particular attention to the URL of each page.
Imagine that you were creating an application similar to SO but were writing it using web forms. How might you construct it?
At a very simple level, in a traditional ASP.NET application, you would probably have two pages: one to list all the questions users have asked and another page to display the actual question and answers.
From the question list page, you would then pass a question ID in the query string through to the detail page and retrieve the relevant answers. For example, when a user clicks a question, the URL might look something like www.stackoverflow.com/questionDetail.aspx?id=3434.
Now click any question in SO, and take a look at the URL. You will see something similar to http://stackoverflow.com/questions/294017/visual-studio-2005-freezes.
This URL is superior to the query string version for a number of reasons:
Search engines index it better than a query string version. At the time of writing, Google seems to give a higher precedence to pages with the search term in the URL.
It's more readable to humans. If you have a product site, it's a lot easier for users to remember an address like www.microsoft.com/vs2010/ than www.microsoft.com/product/productDetail.aspx?id=4563432234.
The URL can assist other developers integrating with your application to understand how it works. For example, if you examine the question detail page (as shown in Figure 13-1), you will see the answer posts to /questions/740316/answer. You can probably figure out that 740316 is an ID for the question, and it wouldn't be too tricky to develop an addition to post answers.
This facility is called routing, and although it isn't specific to ASP.NET MVC, it is an important concept.
|
ASP.NET MVC uses the requested URL to decide how to route users' requests to a special class called a controller that in turn interacts with your application's model.
Before you get started with creating a simple application, you should also be aware of the following:
3.128.171.243