Learn about MVC every day [user-defined controls]

Source: Internet
Author: User

In ASP. NET MVC2, when it comes to user-defined controls, I was so angry that I had to go back and finally read some points.

No more, code attached

1Scenario 1: Custom Controls created through Controller

2 // Controllers : Testascx
4
5 Public Actionresult testascx ()
6 {
7 Ascx = New Ascx ();
8 Return Partialview (Ascx );
9 }
10 // View : Testascx. ascx
11
12 <% @ Control Language = " C # " Inherits = " System. Web. MVC. viewusercontrol <ascx> " %>
13 You can enter what you want to write
14
15   // Call controls
16 View : Index. aspx
17
18 <% HTML. Renderaction ( " Testascx " ); %>

 

 Scenario 2: Call the User-Defined control in ASP. NET mode, for example: footer. ascx

The controller does not need any stuff, but only needs to be called

<% HTML.Renderpartial ("Footer"); %>

 

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.