I have a database column called Template that saves html content , exmaple :
Template = "@section test ".
Now , im trying to replace this dynamically , this section , with specific partial view :
@model CMSFC.Models.Page
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@{
if (Model.Template != null)
{
@Model.Template.Replace("@section test{}",@{ Html.RenderPartial("ViewTest"); } );
@Html.Raw(Model.Template);
}
}
@{
}
This is partial view :
@model IEnumerable<CMSFC.Models.PageConfig>
@{
}
@foreach (var module in Model)
{
if (module.Placeholder == "test" && module.PageId == "test")
{
Html.RenderAction(module.Control, "ContentHtml", new { id = module.Content });
}
<br />
}
This is the controller :
public PartialViewResult ViewTest()
{
return PartialView("ViewTest" , db.PageConfigs.ToList());
}
public ActionResult Details2(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Page page = db.Pages.Find(id);
if (page == null)
{
return HttpNotFound();
}
return View(page);
}
What I have tried:
---------------------------------------------------