ASP. net mvc preview 2 has been released for many days. This period of time has been being studied and applied to actual projects. One sentence I feel about it is:
It's really perfect. It's really rough. . The perfect XHTML is generated. Code I can use the standard DTD of xhtml1.1. The rough content is not mature enough, and the CS code in the view still exists, the title attribute of the control page must be bound to the data of the server control through the codebehind code of view.
If you are not familiar with it yet, view the detailed introduction and tutorials in the road map published by scottgu.
Several key points in this log, the recent memory is getting worse and worse. Is it really old?
1. Configure the routing in iis6.
According to the introduction, IIS6 should have the following route syntax {controller}. MVC/{action}/{ID}. You need to map the MVC extension to aspnet_isapi.dll to process the request. However, in this case, you will not get a perfect URL. This is not what I want! In fact, it is very simple. I can give all the requests to aspnet_isapi.dll for processing. Although the performance consumption is a little bit, the result is immeasurable. The method is Add aspnet_isapi.dll to the wildcard ApplicationProgramIng . To achieve the goal of a perfect URL.
2. Best practices about Form Design
Here, form is the most basic form in the Web (not the web form in traditional ASP. NET ). Code: 1 < Fieldset >
2 < Legend > Fill the following fields: </ Legend >
3 < Form Action = "/Products/Save" Method = "Post" >
4 < P > < Label For = "Pname" > Name: </ Label > <% = Html. Textbox ( " Pname " ) %> </ P >
5 < P > < Label For = "Pcat" > Category: </ Label > <% = Html. Select ( " Pcat " , Viewdata. Categories) %> </ P >
6 < P > < Label > <% = Html. checkbox ( " Prec " , " Recommanded " , False ) %> </ Label > </ P >
7 < P > <% = Html. submitbutton ( " Psubmit " , " Submit " ) %> </ P >
8 </ Form >
9 </ Fieldset >
This is the well formed XHTML code in the view (not html ). A good suggestion is that every input has a label around it. The advantage is that when "name" is clicked, the cursor will automatically locate the pname input text box, of course, its benefits are not just this one. To complete this process, you also need an action: 1 Public Void Save ( String Pname, Int Pcat, String Prec) {
2 Product = New Product ();
3 Product. Name = Pname;
4 Product. categoryid = Pcat;
5 Product. isrecommanded = ! (Prec = Null );
6
7 Datacontext. Products. insertonsubmit (product );
8 Datacontext. submitchanges ();
9
10 Renderview ( " Saveok " );
11 }
You may have seen some very strange code. But I cannot do this for the moment.
Q: Why is the bool type not directly used for the prec parameter of action?
Answer: We know that the checkbox has a checked attribute, but it cannot be obtained in ASP. net mvc at present. It is also because the bool type cannot be used directly.The automatically mapped value is the value of the control value attribute.Instead of other attribute values.
[OK, it's too late, not finishing...]