ASP. NET mvc3 RC2 and some minor bugs

Source: Internet
Author: User

@ ASP was mentioned a few days ago. net mvc3 RC2 has been released. I have to go online to find the publish message. No related publish message is available. I can only find out that it is only for development and download of some subscriber users. However, according to this time point, the external release is not far away. Indeed, on Friday, scottgu officially published an announcement and related releas notes details on its blog, announcing ASP. net MVC 3 (Release Candidate 2). It also briefly introduces the impact of the recently released vs2010 beta1 on mvc3, in fact, it just shows that mvc3 can work in vs2010 and vs2010 beta1 environments.

Previously, mvc3 was highlighted by the tiger, but since it is not our MVC Framework upgrade that affects several projects, we have to postpone the follow-up. The upgrade was not attempted until the RC version was released. As a result, the formcollection's requestvalidation verification problem had to be abandoned halfway. Soon, a month later, and MVC2 also went out of RC2. Let's take a look at what changes it has made.

  • Bugs repair and performance tuning. The bug fix of bugs is the first goal of version update. The bug mentioned above has been solved in my verification, but another bug has been introduced, so I will complain later. Performance Tuning: @ scottgu simply adds that the performance of mvc3 is slightly higher than that of MVC2, but no specific value is specified.
  • Update jquery to 1.4.4, jquery validation to 1.7, and add references to jquery UI by default starting with ASP. NET mvc3. It can be seen that jquery is increasingly reused. I like it, but if I can remove the ASP. NET Ajax script and use jquery to build it in the default environment, I like it better, saving me trouble.
  • Improved view scaffolding, including automatic primary key identification and automatic reference of jquery scripts (which I do not like ).
  • Controllersessionstate is renamed to sessionstate. This attribute allows us to manually disable/read-only sessions.
  • Rename skiprequestvalidation to allowhtml. This attribute allows us to directly ignore requestvalidation verification for a field in the model. However, this function does not work properly in RC2, and a bug occurs. These two renames mainly aim to shorten the attribute name, better meet people's understanding of its actual effect, and reduce the technical naming.
  • Html. Raw (). This helper is mainly used for the razor template engine. Because of Razor's @ output, HTML is called first by default. encode: encode HTML to prevent XSS vulnerabilities. But sometimes we want to output the original value directly. At this time, you can call HTML. raw (). In the aspx engine, we have <%: %> and <% = %>.
  • Dynamic viewbag is a very interesting feature. Regardless of the version before, in this version, both controller and view have a viewbag object, which is a dynamic object, this allows us to dynamically add attributes using traditional objects. For example, in controller, we can add an attribute: viewbag. title. Then, use @ viewbag. Title directly in the view, which is more convenient than the dictionary method. In fact, viewbag is only an encapsulation of viewdata. They actually use the same object. Because ASP. NET MVC2 is built on. NET 3.5 without the dynamic syntax, mvc3 supports only. Net 4.0.
  • The output cache is improved. You do not need to manually specify varybyparam for outputcache. The parameter of action is automatically used as the cache expiration condition. I have not used the outputcache function yet.
  • @ Model: Specifies the definition line of a strong view in razor. No space is output.
  • The improvement of HTML. validationmessage gives priority to "most valuable" error messages, rather than simply displaying the first error message. So what is the "most valuable" Priority error message? When the model is bound, multiple error messages are saved in modelstate, including the return values of validate for implementing the ivalidatableobject interface, which are used to verify messages in the validationattribute attribute, and the exception triggered when accessing this attribute. In general, exceptions are not provided to end users, but for developers for debugging. Therefore, when an error message is displayed, the error message without exception is displayed first. Only when this error message is not displayed will a general message with an exception be displayed. A little more. Normally, the ivalidatableobject interface is available only because of the basic. Net 4.0 interface.ProgramSet, Based on. NET 4.0 is too important.
  • Remoteattribute, which can be used to quickly implement Ajax server-side verification.
  • Viewresult, which has two attributes: Model and viewbag.
  • Additionalmetadataattribute, which is also very important. In many cases, it is quite troublesome to add additional values other than existing attributes in modelmetadata, and it is not necessarily necessary for other attributes. At this time, additionalmetadataattribute plays a major role:
    Public class productviewmodel {[additionalmetadata ("adminonly", true)] Public String refundcode {Get; Set ;}}

    In this way, we can use modelmetadata. additionalvalues to obtain our additional defined metadata.

  • The improvement of labelfor is more in line with W3C standards. The value of label for should be the ID of element rather than name.

I have listed the important release notes. The last two points are not mentioned by scottgu. For more details, see the complete release notes. The following is a small complaint. Another bug occurred while verifying whether the formcollection verification bug was fixed. That is, when I use allowhtml in attributes, I can allow the input of HTML values as described in the document, and an verification exception will still be reported. At first, I thought I still needed to set requestvalidationmode = 2.0 and use the Authentication Mode of ASP. NET 2.0. You only need to check it on the Internet. This is a known bug. Fortunately, the solution is not complicated. You only need to modify modelmetadataprovider:

Modelmetadataproviders. Current = new dataannotationsmodelmetadataprovider ();

The cause of this bug is that system. Web. MVC. cacheddataannotationsmodelmetadataprovider is used by default.CodeOther functions of mvc3 are not affected, but modelmetadata is not cached. It may also be because a similar cache is added to mvc3, which improves the running speed?

I have to say that in mvc3, we do not need to set requestvalidationmode = 2.0. This is very important!

According to the official statement, mvc3 RTM will be released in March. If R2 has no other bugs, I am willing to upgrade it. After all, the progress is still great. But it's just unobtrusive Js. I still don't like it very much or don't like it very much.

Click the download link.

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.