Introduction to new features of Asp.net MVC 3 beta

Source: Internet
Author: User

After the National Day holiday, I just caught up with Asp.net MVC 3 beta release and shared my experience with you.

 

The first step is to change the selection interface when creating a project:

1. View engine changes.

The view engine razor is added to Asp.net MVC 3.

If index. aspx and index. cshtml are the same in the created Project, the default MVC view is Aspx. However, you can add the following code to the application_start method in the global. asax file so that MVC can first execute the index. cshtml page of the razor engine.

The Code is as follows:

Viewengines. Engines. Clear ();
Viewengines. Engines. Add (New razorviewengine ());
Viewengines. Engines. Add (New webformviewengine ());

 

2. You can modify the attribute display sequence in the model at will.

In previous versions, if we create a model as follows:

Public class employee
{
Public String firstname {Get; set ;}
 
Public String lastname {Get; set ;}
 
Public int employeeid {Get; set ;}
}

The following code creates a view for this model:

<% @ Page title = "" Language = "C #" masterpagefile = "~ /Views/shared/site. Master"
Inherits = "system. Web. MVC. viewpage <mvc3beta. Models. Employee>" %>
 
<Asp: Content ID = "content1" contentplaceholderid = "titlecontent" runat = "server">
Employee details
</ASP: content>
 
<Asp: Content ID = "content2" contentplaceholderid = "maincontent" runat = "server">
<%: HTML. editorformodel (model) %>
</ASP: content>

 

After running, you can see that the attributes of the employee class are shown as follows:

In Asp.net MVC 3, we can set the display sequence of attributes to flexibly modify the positions of fields on the view page. For example:

 

Run the program again, and the display of employee is as follows:

 

 

 

3. Added the grid control.

We will use the above employee to create a grid:

Show the Controller code:

 

View section. We use the webgrid in the system. Web. helpers class to display the preceding information about the employees.

 

 

The result is as follows:

We set 'firstname' to sort. You can change the sorting by clicking the header of another column.

 

4. added the chart component.

Let's use the relationship between employee and sales to create a bar chart showing employee sales performance.

We create a model named employeesale.

 

Add a showchart control in the controller section:

 

Finally, View:

 

 

Note that the chart control is displayed by creating a temporary PNG image. After the page is accessed, the PNG image is not saved on the server.

 

Running effect:

 

For more new features, see release notes. Other functions, such as IOC,

Code download

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.