Jun 08, 2015, 2:42 PM
Render Dynamic Control in View
I have the following code which generates a dynamic control based on Model.ChildControlBaseID. However the rendered page seems to render control.ToString() and not the control's dom elements.
@using Ext.Net
@using Ext.Net.MVC
@using cr.DomainObjects.Core
@using common.Ext.Controls
@model mfx.v3.ViewModels.DashboardBaseViewModel
@{
Layout = null;
ViewBag.Title = "MFX - Route Management";
var X = Html.X();
ControlModel controlModel = ControlHiearchyService_01.GetControlHierarchyDefinition(Model.ChildControlBaseID, Model.CurrentUser.UserID);
controlModel.Request = this.Request.RequestContext;
controlModel.CurrentUser = Model.CurrentUser;
ControlBase control = controlModel.Controls.SingleOrDefault(t => t.ControlBaseID == Model.ChildControlBaseID);
AbstractContainer ctr;
if (control.ControlType == cr.DomainObjects.Core.ControlType.Container)
{
ctr = ControlHiearchyService_01.GetContainerDefinition(controlModel);
}
else if (control.ControlType == cr.DomainObjects.Core.ControlType.Panel)
{
ctr = ControlHiearchyService_01.GetPanelDefinition(controlModel);
}
else
{
ctr = ControlHiearchyService_01.GetGridPanelDefinition(controlModel);
}
ctr.Height = 1000;
ctr.ViewContext = this.ViewContext;
ctr.HtmlHelper = this.Html;
ctr.Render(RenderMode.Auto);
}
<html>
<head>
<title>@ViewBag.Title</title>
<link href="~/content/css/crXOverride.css" rel="stylesheet" />
<script src="~/content/js/common.js"></script>
</head>
<body>
@Html.X().ResourceManager(ViewBag.ManagerConfig as MvcResourceManagerConfig)
@ctr
</body>
</html>