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: