Learn ASP. net mvc (Article 3) Practice

Source: Internet
Author: User

Undertake the above Learn ASP. net mvc (second) Practice
Create Controllers and Views
Let's review the basic workflow of ASP. net mvc:
URL --> Controller (a method Action will be executed) --> get a Model object from the database --> pass the Model as ViewData to View (Detail. aspx ).
Unlike the traditional Web architecture, the request URL is mapped not to a specific file but to a class method. These classes are Controller controllers in MVC. They are responsible for processing incoming requests and user input, receiving and storing data, and return the result to the client (displaying HTML, downloading files, or redirecting to different URLs ).
For example, if you request http: // localhost: 2121/Account/LogOn, a Controller named Account and an Action named LogOn are displayed.

Add UsersController Controller
Right-click the Controllers folder in the Web project and choose Add-> Controller:

Add a Controller named UsersController. By default, vs generates the following code for us:

Public class UsersController: Controller
{
//
// GET:/Users/

Public ActionResult Index ()
{
Return View ();

}
}

Here we will make a simple modification:

Public class UsersController: Controller
{
//
// GET:/Users/

Public void Index ()
{
// Return View ();
Response. Write ("}

//
// GET:/Users/Details/1
Public void Details (int id)
{
Response. Write ("}


}

Run the project and enter http: // localhost: 2121/Users in the address.


The above two address requests are requests that obtain all Users information, and requests that pass serial numbers or obtain detailed information. So what does MVC obtain the corresponding Controller? Anyone familiar with ASP. net mvc should know that ASP. net mvc Routing

  • Four pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • 4
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.