Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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)
            {
                // Response.Write(Model.Template);
                //  Model.Template.Replace("@section test{}",) me partial view per cdo section
                @Model.Template.Replace("@section test{}",@{ Html.RenderPartial("ViewTest"); }   );
                @Html.Raw(Model.Template);
            }
        }
@{
    //Html.RenderAction("Test", "Pages");
}

This is partial view :
@model IEnumerable<CMSFC.Models.PageConfig>
@{
    //    Layout = "~/Views/Shared/_Layout2.cshtml";
}

@foreach (var module in Model)
{
    if (module.Placeholder == "test" && module.PageId == "test")
    {
        //   Html.RenderAction("NewsList", "ContentHtml")
        Html.RenderAction(module.Control, "ContentHtml", new { id = module.Content });

        //  @Html.DisplayFor(modelItem => module.Control)   ;
    }
    <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(db.PageConfigs.ToList().Where(m => m.PageId == "test").ToList());
	return View(page);
  //  return View(page);
}


What I have tried:

---------------------------------------------------
Posted
Updated 6-Sep-17 22:55pm
v2
Comments
Graeme_Grant 7-Sep-17 4:56am    
Please stop throwing code at the wall hoping that it will stick. Why must we debug your code all the time when you won't do it yourself? It is called programming. Watch this video: Basic Debugging with Visual Studio 2010 - YouTube[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900