Super simple: Step by Step teaches you to create a small Asp.net MVC application

Source: Internet
Author: User
Super simple: Step by Step teaches you to create a small Asp.net MVC application

This tutorial will help you create a small Asp.net MVC example.

In this tutorial, we will create our own model, view, and controller so that they can work together. Here, use Visual Studio to create a new Asp.net MVC applicationProgram. The purpose of this tutorial is to use the MVC principle to output information on the Web page. A simple understanding of what we plan to do, then we will demonstrate each step to build our website. For our goals, we need a model to save information. This model will be a class with the necessary attributes. Then, we will create a view to display information in a table form. Finally, we need a controller to accept the webpage request and respond to it. Let's get started.

Create model

Right-click the models folder and use add-> class to create a new class, as shown in the following figure:

Name the class personalinformation. CS. Add the following attributes to the model:

Use the C #3.0 specification to create these attributes. We do not need to create private fields for them. This completes our model. Now let's create our view. We will use it to display information in the browser.

Create View:

Right-click the views folder and create a new folder. Name it "personalinformation. Right-click the personalinformation folder and choose add-> View:

Name the view as index, select "Create a stronugly-typed View", and then select class, which acts on the model of the view. In the View data class drop-down box, you may not see any view class. Compile the application and add a view. You will see the personalinformation class in the drop-down box. Select a dashboard page for your view. Once these steps are completed, click Add and the created view. See.

Create a controller:

Now we have completed model and view. Let's create our controller. Right-click controllers and select Add-> Controller

Name the Controller as personalinformation. Make sure that the controller name is the same as that created in the Views folder.

You will see a default method named index in the Controller class.

This method has an actionresult type that returns a view. In future tutorials, we will explore the return types and their details in depth. Now let's make some code and pass the model to the view so that it can display information on the webpage. In the followingCodeEnter it in your controller class.

This Code creates a model and fills data for it. The last step is to use the information displayed in the view. For the open view we created, enter the following code:

That's it. We have completed our model, view, and cintroller. Now let's compile and run our applications. Below is the final output, which we will see in the browser. Observe the URL in the browser address bar carefully.

 

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.