Currently, the project requires page adjustment by module.. net mvc user control is implemented to split the page into multiple modules. Each module is a user control. You can drag and drop the module to adjust the page layout and save it as configuration information, then the Controller reads the personalized configuration of each user and loads and parses the control in the action, and then presents it to the view. The following is the code for dynamically parsing the user control:
Public ActionResult Design (string shopid)
{
Var page = new System. Web. Mvc. ViewPage (); // create an MVC Page Object
// Create a custom control that is of the MVC type
ViewUserControl calendar = (ViewUserControl) page. LoadControl ("~ /Components/Design. ascx ");
StringWriter output = new StringWriter ();
ViewData ["data"] = "data ";
Using (var sw = new System. Web. UI. HtmlTextWriter (output ))
{
Page. Controls. Add (calendar); // Add a user control to the page. Independent Controls cannot be parsed.
Calendar. ViewData ["data"] = "data"; // value ViewData
Page. RenderControl (sw); // parse the control
// System. Web. HttpContext. Current. Server. Execute (page, sw, true );
ViewData ["control"] = sw. InnerWriter. ToString (); // output parsed content
}
Output. Dispose ();
Return View ();
}
Control Code:
<%@ Control Language="<span class="wp_keywordlink_affiliate"><a href="http://www.tangdou.net/tag/c/" title="C#" target="_blank">C#</a></span>" AutoEventWireup="true" CodeBehind="Design.ascx.cs" Inherits="NewTang.Components.Design" %><div>design:<%=ViewData["data"] %></div>
My blog: www.mikel.cn
Shundao recruitment program ape and siege lion engaged in ASP. net mvc development