Model view controller 如何使用MVC razor视图在Iframe中绑定HTML内容? 在项目中创建TestModel类,如下代码所示。

Model view controller 如何使用MVC razor视图在Iframe中绑定HTML内容? 在项目中创建TestModel类,如下代码所示。,model-view-controller,iframe,Model View Controller,Iframe,下面是代码writest.cshtml页面,并获取控制器中要查看的模型列表 @using test.Helpers; @model List<test.Entities.TestModel> @{ ViewBag.Title = "Template"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Index</h2> <table class="table"> <

下面是代码writest.cshtml页面,并获取控制器中要查看的模型列表

@using test.Helpers;
@model List<test.Entities.TestModel>

@{
    ViewBag.Title = "Template";
    Layout = "~/Views/Shared/_Layout.cshtml";

}

<h2>Index</h2>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model[0].EmailTemplateId)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].TemplateName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].TemplateContent)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].CreatedDate)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].UpdatedDate)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].IsDefaultTemplate)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].TemplateKey)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].TemplatePath)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].TemplateJson)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].IsAdmin)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].TemplateType)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].TemplateTag)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.EmailTemplateId)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.TemplateName)

            </td>
            <td>


**`<iframe id="testiframe" class="iframe" src=@item.TemplateContent></iframe>`**

            </td>
            <td>
                @Html.DisplayFor(modelItem => item.CreatedDate)
            </td>
            <th>
                @Html.DisplayFor(model => item.UpdatedDate)
            </th>
            <th>
                @Html.DisplayFor(model => item.IsDefaultTemplate)
            </th>
            <th>
                @Html.DisplayFor(model => item.TemplateKey)
            </th>
            <th>
                @Html.DisplayFor(model => item.TemplatePath)
            </th>
            <th>
                @Html.Raw(item.TemplateJson)
            </th>
            <th>
                @Html.DisplayFor(model => item.IsAdmin)
            </th>
            <th>
                @Html.DisplayFor(model => item.TemplateType)
            </th>
            <th>
                @Html.DisplayFor(model => item.TemplateTag)
            </th>
            <td>
                @*@Html.ActionLink("Edit", "Edit", "Test", new { id = item.Id }, null) |
                    @Html.ActionLink("Details", "Details", "Test", new { id = item.Id }, null) |
                    @Html.ActionLink("Delete", "Delete", "Test", new { id = item.Id }, null)*@
            </td>
        </tr>
    }

</table>
@使用test.Helpers;
@模型列表
@{
ViewBag.Title=“模板”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
指数
@DisplayNameFor(模型=>模型[0].EmailTemplateId)
@DisplayNameFor(模型=>模型[0].TemplateName)
@Html.DisplayNameFor(模型=>模型[0].TemplateContent)
@DisplayNameFor(模型=>模型[0].CreatedDate)
@DisplayNameFor(模型=>模型[0].UpdateDate)
@DisplayNameFor(模型=>模型[0].IsDefaultTemplate)
@DisplayNameFor(模型=>模型[0].TemplateKey)
@DisplayNameFor(模型=>模型[0].TemplatePath)
@DisplayNameFor(模型=>模型[0].TemplateJson)
@DisplayNameFor(模型=>模型[0].IsAdmin)
@DisplayNameFor(模型=>模型[0].TemplateType)
@DisplayNameFor(模型=>模型[0].TemplateTag)
@foreach(模型中的var项目)
{
@DisplayFor(modelItem=>item.EmailTemplateId)
@DisplayFor(modelItem=>item.TemplateName)
**``**
@DisplayFor(modelItem=>item.CreatedDate)
@DisplayFor(model=>item.updateDate)
@DisplayFor(model=>item.IsDefaultTemplate)
@DisplayFor(model=>item.TemplateKey)
@DisplayFor(model=>item.TemplatePath)
@Html.Raw(item.TemplateJson)
@DisplayFor(model=>item.IsAdmin)
@DisplayFor(model=>item.TemplateType)
@DisplayFor(model=>item.TemplateTag)
@*@ActionLink(“编辑”、“编辑”、“测试”,新的{id=item.id},null)|
@ActionLink(“详细信息”、“详细信息”、“测试”,新的{id=item.id},null)|
@ActionLink(“删除”,“删除”,“测试”,新的{id=item.id},null)*@
}
在图片下方显示输出。 Iframe正确,但不在模型列表中显示Html内容。请给出答案



您是否考虑过将HTML加载到容器中

<div id='@item.EmailTemplateId'></div>
<script type="text/javascript">
    $(document).ready(function(){
        $('#@item.EmailTemplateId').load('@item.'); 
    });
</script>

$(文档).ready(函数(){
$(“#@item.EmailTemplateId”).load(“@item”);
});
将旧代码替换为以下代码

<iframe id="testiframe" class="iframe" src=@item.TemplateContent></iframe>


我解决了这个问题

<div id=@item.EmailTemplateId style="height:200px; overflow:scroll;">@Html.Raw(HttpUtility.HtmlDecode(item.TemplateContent))</div>

@Html.Raw(HttpUtility.HtmlDecode(item.TemplateContent))

感谢您回答我的问题,但我想在iframe中显示。我已经在视图中使用了@foreach循环,因此不适用于meIt应该可以在循环中使用,因为我们为容器提供了来自模型的id。所以它对每一行都是唯一的,``应答工作正常,但不能在iframe中使用div部分。
<iframe id="testiframe" class="iframe" src=@item.TemplateContent></iframe>

<div id=@item.EmailTemplateId style="height:200px; overflow:scroll;">@Html.Raw(HttpUtility.HtmlDecode(item.TemplateContent))</div>