0

I have TinyMCE editor in my custom site CMS and store HTML content in SQL DB.

Then I render it in cshtml RazorView:

@MvcHtmlString.Create(Model.Content)

How can I include PartialView inside html content by TinyMCE?

Something like:

...content html...
<div>[[ViewName]]</div>
...content html...

2 Answers 2

3

A partial view can be included in an HTML page by using the following

<% Html.RenderPartial("~/Views/Folder/ViewName.ascx");%>

Sign up to request clarification or add additional context in comments.

Comments

0

You could execute the Partial View and set the resultant html as the content for TinyMCE.

private string ProduceViewResult(string viewName, object model)
{
  ViewData.Model = model;

  using (var sw = new StringWriter())
  {
    var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
    var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
    viewResult.View.Render(viewContext, sw);
    viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
    return sw.ToString();
  }
}

Usage

var partialViewHtml = ProduceViewResult("PartialViewName", myModel);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.