Rebuilding programmer Capability (3)-asp.net MVC Framework adds controller

Source: Internet
Author: User

The framework provided by MVC in Microsoft is now only found to be ASP. Another 8 years ago, I made an MVC Windows app framework if interested I will introduce to you in the future, welcome everyone's attention. MVC concept on the site there are a lot of people go to look must be able to see, here do not repeat the story. Here is just a description of how to add.

1. Locate the ASP. NET project, then go to the Controller folder, right-expand menu [Add] to expand the next Level menu, then select [Controller].

2. There are 3 options in the dialog box, this time to express the convenience of the first empty MVC5 controller

3. Fill in the name of the controller and click Add.

It is important to note that the controller is the necessary end. This is the MVC framework for routing.

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;

Namespace Webmvcapp.controllers
{
public class Reqordercontroller:controller
{
Get:reqorder
Public ActionResult Index ()
{
return View ();
}
}
}

The newly created CS file is similar to this.

3. Write a simple example of adding a welcome method to the controller's code

Get:reqorder
public string Welcome ()
{
Return "This was app for request Order submit.";
}

This code returns a string of characters as soon as the welcome of the controller is called. Similar to the output of HelloWorld.

4. You can test it by F5.

It's not the same as it was written, right, the current page is the default page, and there is no controller processing location just written.

5. Test controller

Add the Controller and the methods that need to be tested in the service portal.

The page that is displayed is just the thought.

Unlike other web pages, the return is really just a string, not an HTML page, you can use the right-click menu to look at the code.

Summarize

1.Controller must have "Controller" at the end of the new, you need to pay attention to casing specifications Oh.

2. When the controller is called, the address of the page access, the server root address, the controller's name does not contain the controller part, and then add the method name.

#补充:

    • I have seen the API data, in the public number configuration, you need to verify that the server-side address is configured correctly, will be the configured address to call the Web page, and then ask the server to reply

Rebuilding programmer Power (3)-asp.net MVC Framework Add controller

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.