HTML不显示在Controller中创建的View中

时间:2019-04-03 18:35:28

标签: c# asp.net-mvc

当我在控制器中创建方法时,我希望在视图中显示HTML输出。虽然我看到的功能结果与预期的html相同,但它并未显示在页面中。

我已经尝试过HtmlHelper Html.Raw

       <table class="table table-bordered table-framed" id="seconDTable" style="display:block;height:100%;">
                        <tbody>
                            @if (caseFile.Length > 0 && RenamedCaseFileName.Length > 0)
                            {
                                <tr>
                                    <td style="width: 100%;">
                                        <input type="checkbox" id="CheckBox" title="Select All Bookmarks" onchange="changeCheckBox();" class="styled" />
                                        <span>Select All</span>
                                    </td>
                                </tr>
                                if (oGdPicturePDFstatus == GdPicture14.GdPictureStatus.OK)
                                {

                                    int rootID = oGdPicturePDF.GetBookMarkRootID();
                                    oGdPicturePDFstatus = oGdPicturePDF.GetStat();

                                    if (oGdPicturePDFstatus == GdPicture14.GdPictureStatus.OK)
                                    {
                                        IHtmlString str = new HtmlString(GetPDFBookmarks.ParseBookmarksOutlines(oGdPicturePDF, rootID, 0));
                                        Html.Raw(str);
                                    }
                                    else
                                    {
                                        if (oGdPicturePDFstatus == GdPicture14.GdPictureStatus.PropertyNotFound)
                                        {
                                            <tr>
                                                <td style="width: 100%;">
                                                    This PDF document doesn't contain any bookmarks.
                                                </td>
                                            </tr>
                                        }
                                    }
                                }
                                oGdPicturePDF.Dispose();
                            }
                        </tbody>
                    </table>

功能:

                       public string ParseBookmarksOutlines(GdPicturePDF oGdPicturePDF, int bookmarkID, int level)
                                {
                                    string title = "";
                                    GdPictureStatus status = GdPictureStatus.OK;
                                    string cssType = string.Empty;
                                    string TableRows = string.Empty;
                                    while (true)
                                    {
                                        title = oGdPicturePDF.GetBookMarkTitle(bookmarkID);
                                        status = oGdPicturePDF.GetStat();

                                        if (level == 0)
                                        {
                                            cssType = "ParentsourcefileCheckBox";
                                        }
                                        else
                                        {
                                            cssType = "ChildsourcefileCheckBox";
                                        }

                                        if (status == GdPictureStatus.OK)
                                        {
                                            TableRows = TableRows + "<tr><td style=\"width: 100 %; \">";
                                            TableRows = TableRows + "<input name=\"sourcefileCheckBox\" type=\"checkbox\" class=\"" + cssType + "\" id=\"checkBox\" value=\"" + bookmarkID + "\" />";
                                            TableRows = TableRows + "<span>" + title + "</span>";
                                            TableRows = TableRows + "</td></tr>";

                                        }
                                        else
                                        {
                                            TableRows = TableRows + "<tr><td>";
                                            TableRows = TableRows + "Title: this error occurs - " + status.ToString() + "    Level: " + level.ToString() + "\n";
                                            TableRows = TableRows + "</td></tr>";
                                            //message = message + "Title: this error occurs - " + status.ToString() + "    Level: " + level.ToString() + "\n";
                                        }
                                         if (bookmarkID == 0)
                                        {
                                            break;
                                        }

                                    }

                                    return TableRows;
                                }

我希望复选框显示在最终呈现的页面上,而不是全部显示。

enter image description here

1 个答案:

答案 0 :(得分:1)

答案如下:

 @Html.Raw(HttpUtility.HtmlDecode(GetPDFBookmarks.ParseBookmarksOutlines(oGdPicturePDF, rootID, 0)));

它位于帖子中: Return html string from controller and display in view