Asp. Net MVC5 getting started learning series ⑤

Source: Internet
Author: User
Tags actionlink

Check the VS production editing method and form

In the previous step, we used a strong type. When we created a Controller, VS implemented CURD by default. In this article, we will simply look at the Code implemented by default. VS is always powerful, but it is also convenient to weaken us. Of course, this is for efficiency, if we are a newbie, we recommend that you do not steal the laziness. Why? Don't explain .....

We open the Movie class of the object we created, and then add some identification features on the ReleaseDate attribute, as shown below:

We set the general attributes of the ReleaseDate attribute as well as its type and the format of its dynamic data display in Asp.net. Then we run the simple program we wrote. The effect is as follows:

Here we can see that the classic read RoutConfig of MVC. cs routing mechanism. Is this similar to {controller}/{action}/{id }........., in fact, there is an ActionLink method on the page to help produce such a dazzling html hyperlink tag and open the index. on the cshtml page, let's take a look at the unique ActionLink of MVC. Its appearance is as follows:

What are the parameters in it!

Let's take a look:

To put it bluntly, you need to give the link a name, and then continue to look at it:

To put it bluntly, you need to go to the method or action. here you need to give the method name (action name) of the target, and then let's see what the last parameter is:

This is A long string, which means you want to pass parameters. If there are multiple parameters, such as A and B, you can write them like this:

@ Html. ActionLink ("xxxx", "xxxx", new {value1 = item. A, value2 = item. B}). Multiple parameters are separated by commas.

OK, continue with the figure running the above program. Let's continue the editing process. When we click the Edit hyperlink, the program will do the following:

Then you will see the following page:

At the same time, when we click the Edit button on the homepage, HTTP sends a GET request to the Edit Method in the Controller. Note that there are two Edit methods, but they are not very large, in terms of code, the first Edit is responsible for receiving the Get request Edit action, and the second is responsible for receiving the Post request action, the first thing you actually do is to give me parameters. I will show you the data and place it on your editing page, the second thing you do with Edit is that you modify the page data and POST it to me. I am responsible for saving it in the database. This is a personal intuitive explanation.

You may note that the POST action method has such an identifier, for example:

In fact, I was curious when I first created it, But I tried several times to produce such a thing on the Action. As a result, this should be an improvement place starting with mvc4! This identity attribute is actually used to block forged requests, and this Bind (Includ = "x, x") does something. Let's take a look, its responsibilities are as follows:

In plain text, it is responsible for binding parameters here, but this parameter is the attribute name of our Model. If the Controller blocks forged requests, then there is forged data. Should the View layer coordinate the work with the ID? We open the Eidt. take a look at the cshtml page. Its appearance is as follows:

 

Is there a coordination between the front-end and the backend identity that prevents forged requests, and a hidden domain is also put to store IDs, as you can see, this form is a bit like the ValidationSummary control in the asp.net data verification control, but here it is changed, in essence it is not changed... If you are interested, you can study it in depth.

Let's take a look at the effects of forged input data, as shown below:

The Edit process is almost finished here.

In the future, we will continue to learn the beginner series of knowledge. So far, VS has helped us a lot of things, and we are all learning the production code, in the future, we will make a query to experience the process in person...

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.