I'd like to keep in the database the list of the "Modules" which are in fact Partial Views of the ASP .NET MVC.
Is it possible to define that dynamically?
HTML
<p>A Partial Control</p>
@Html.Partial("UserControls/ColorBlockUserControl", new ColorModel())
<hr />
<p>A Partial Control that is initialized on Server-Side</p>
@{
Html.RenderAction("InitializeUserControl");
}
C#
public class HomeController : Controller
{
public ActionResult Index()
{
return View(new HomeModel());
}
public ActionResult InitializeUserControl()
{
ColorModel colorModel = new ColorModel
{
Width = 200,
Height = 200,
RGBColor = "#FF0000"
};
return PartialView("UserControls/ColorBlockUserControl", colorModel);
}
}
I assume to use ViewBag to use like
@ViewBag.InitializeUserControl = "InitializeUserControl"; // It goes from the database and can be ANY name
Html.RenderAction(@ViewBag.InitializeUserControl);
But it is not working...
I hope u got the idea to define it
Html.RenderAction("I need here the dynamic var");
Thanks!
P.S. To make it clear the final idea is provide to the user editable template (CKEditor) so user can add any ASP .NET MVC UserControl name i.e. "Gadget1" or "Gadget2" and we are able dynamically change WebPage and show all controls which have been added dynamically.
CS1973: 'System.Web.Mvc.HtmlHelper<MVCColorUserControl.Models.HomeModel>' has no applicable method named 'RenderAction' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.CS1973: 'System.Web.Mvc.HtmlHelper<MVCColorUserControl.Models.HomeModel>' has no applicable method named 'Partial' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.