我正在为单页 CRUD 应用程序尝试使用 knockout.js,在几乎所有方面,它似乎都比使用 ajax 将部分页面加载到 View 中更好,但我遇到的一件事是呈现文本区域在解析的 html 中,我得到了所有标签 <p>
等
当我使用 Razor/C# 时,我只会使用 @Html.Raw(Model.Details)
但是现在我正在使用 <td data-bind="text: Details"></td>
.
我试过了<td>@Html.Raw(new { @data_bind="text: Details" })</td>
但没有运气。
解决这个问题的最佳方法是什么?
最佳答案
如果您的 View 模型中有 HTML,则需要 html
binding显示它:
The
html
binding causes the associated DOM element to display the HTML specified by your parameter.Typically this is useful when values in your view model are actually strings of HTML markup that you want to render.
所以你的代码应该是这样的:
<td data-bind="html: Details"></td>
关于javascript - 表数据不使用 ko.js mvc 显示为 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35412561/