How to render Razor in cshtml page with Servicestack without content page

折月煮酒 提交于 2019-12-13 05:20:33

问题


I have markdown in string property of my model and would like to render it onto page. If I have html in that same string property I would simply do:

@Html.Raw(Model.BodyHtml)

Is there a same thing if string contains Markdown rather than Html? I.e. something like:

@Html.MarkdownToHtml(Model.BodyMarkdown)

回答1:


The new @Html.RenderMarkdownToHtml() API for this has just been added in v4.0.34+ that's now available on MyGet, which will let you render markdown with:

@Html.RenderMarkdownToHtml(Model.BodyMarkdown)

In earlier versions of ServiceStack you would call the Markdown implementation itself to render HTML and use the AsRaw() extension method so the returned HTML isn't automatically encoded, e.g:

@(new MarkdownSharp.Markdown().Transform(Model.BodyMarkdown).AsRaw())


来源:https://stackoverflow.com/questions/27199738/how-to-render-razor-in-cshtml-page-with-servicestack-without-content-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!