ASP. net mvc display UserControl (extensions)

Source: Internet
Author: User

Last night, Insus. NET had a nostalgia for "Never forget, ASP. net mvc shows WebForm Web page or UserControl Control" http://www.cnblogs.com/insus/p/3641610.html that is only a small attempt, there are many unknown places.

That article contains the Render user control ascx. Now, Insus. NET wants to refactor it to make concessions that it can be used in the Action or Razor syntax.

 

Create an AscxUtility. cs, which can be used in multiple places in the application.

In this way, we can reconstruct the public ActionResult UcTest () Action last night.

 

Comment out Code marked 1, restructured to marked 2. In this way, we can use the Utility we just created.

The effect is the same after running:

 

 

If we want to use the Razor syntax, how can we implement it? It doesn't matter, anyway, there is a previous exercise "Custom MVC Helper Extension Method" http://www.cnblogs.com/insus/p/3379485.html, then we will add an extension method in this class:

 

To demonstrate this extension method, we add a new Action to the Controller and create a view:

 

View:

 

Preview result:

 

 

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.