ASP. net mvc Preview3 has just released a bug. It is not just intended to bring it to the cold water, but to better discuss, learn, and use it with everyone, so that everyone can make progress together.
The main difference between Pre3 and Pre2 has been clearly displayed on Scott's Blog, and an official upgrade document is provided: Prepare.
Today I have read several key points and found that there is not much change in the use of ActionURL, but there is a small problem in obtaining it:
1. For example, when you try to output Url. Action ("Foo") in AdminController (corresponding View), it is expected to return/Admin [. mvc]/FooBut unfortunately, when you add a Foo Action in HomeController,Add a Home/Foo URL rule to global. asax. cs (no problem will occur if you do not add the rule)When you use Url. Action ("Foo"), the returned results may be as follows:/Home [. mvc]/FooTo ensure persistent availability, We must discard the Url. action ("Foo"), instead use the rewrite method: Url. action ("Foo", "Admin "). This is not only the case with Url. Action, but also with Html. ActionLink. I have repeatedly tested IIS/VS and routes. MapRoute/routes. Add, and the results are the same. This is disgusting. I don't know if it's my environment issue or the same is true for everyone's test results? Thank you for your feedback!
Download this bug instance: http://files.cnblogs.com/szw/ASP.NET_MVC_Preview_3_-Routing_bug-1.rar
Key test code:
Global. asax. cs:
Routes. MapRoute (
"About", // Route name
"Home/About", // URL with parameters
New {controller = "Home", action = "About"} // Parameter defaults
);
/Views/Admin/Index. aspx:
Ideal: Url. action ("About") and Url. action ("About", "Admin") outputs the same: <% = Url. action ("About", "Admin") %> <br/>
Actual Url. Action ("About") Output: <% = Url. Action ("About") %>
Output result:
In addition, here we will summarize the status of bugs (or deficiencies) found in the previous two Preview versions:
These problems are published in the use of Microsoft ASP. net mvc Framework + collect feedback on bugs found by garden friends, using Microsoft ASP. net mvc Framework experience + collect feedback on bugs found by garden friends [Supplement] and the radical solution for bugs found in MVC Toolkit Part (1)
1. Some of the problems mentioned in the first article still exist more or less, but this does not indicate that they are all problems of MVC, and some are. some features of NET3.5, such as Linq to SQL, have some problems in use and "cooperation.
2. Many of the scaling methods in HtmlHelper mentioned in the first and second articles are messy. This time, In Preview3, all the sizes, attributes such as maxLength are stored in the htmlAttributs attribute, Which is refreshing. pay more attention when upgrading and using maxLength.
3. The third Part of MVC Toolkit has found that the problem mentioned in Part (1) of the radical solution of the bug seems to have been perfectly solved in Preview3.
Notes:
The official upgrade document contains the following paragraph:
· Dit the Default. aspx file and add the following line:
<% Response. Redirect ("~ /Home ") %>
This redirect is not necessary for IIS 7. This is a workaround for an issue with how the Web server that is built into Visual Studio (the ASP. NET Development Server) works with routing.
This indicates finding Default. aspx and adding this code: <% Response. Redirect ("~ /Home ") %>. This is not required in IIS7, So that you need to use this as a "stepping stone" for the root directory when testing IIS with VS or below IIS7 ". Thanks a friend Leven for reminding me that if you use the Preview1/2 template, Language = "C #" is not set for default. aspx. The default value is VB. NET, Response. Redirect ("~ /Home "). If C # is used, add a"; ". Here we need to add a point that is not clearly stated in the document: Just ("~ /Home ") is invalid for IIS7 or lower environments (of course, in the Preview3 template, in default. aspx. this jump has been added to the Page_Load of cs and must be directed to default. aspx. view or modify in cs. According to the execution sequence of Page_Load and aspx pages, the setting on the aspx page will be invalid.) When upgrading from Preview1/2, pay attention to "~ /Home "must be the same as the previous version to modify global. asax. cs. If IIS7 is not used, a custom extension, such as. mvc --"~ /Home. mvc ".
There is another expectation:
1. Html. dropDownList (original Html. select) the data source type can be richer, especially the IDictionary <string, object> type data source is directly accepted (currently, due to the IDictionary <string, object> htmlAttributes Rewriting Method, this type is considered as a set of attributes ). Of course, this can still be done in new SelectList (), but it is better to bind the key-value directly to the Html input box in the form of "value-text, at present, you need to expand some methods to achieve this.
2. Preview3 must be input in RenderView. aspx /. ascx file name requirements, you can directly View () according to the Action name; and each Action must return a ResultAction type, at this time, we can return RedirectToAction (actionName) to execute another Action (RedirectToAction returned is also the ResultAction type), but I think of a more convenient method (I do not know if it is officially used) -- directly return actionName () -- this method not only facilitates input, but also helps to check the correctness of actionName during compilation, as well as the correctness and convenience of passing parameters. Because the return type is ResultAction. After I tried it, I found it was feasible, but there was a problem related to the View () method: for example, in Action1, return Action2 (); In Action2, I only View (), no View ("Action2"). At this time, because the method name is still Action1, when running to View () of Action2, it will automatically find Action1.aspx/ascx, rather than action2. It is a bit regrettable here. If the View () method can be enriched to find the name of the method directly to which it belongs, this function will be more perfect.
More details are still being confirmed. You are welcome to add them. I will summarize them together!