2

我正在使用 razorpdf 在我的 mvc 4 应用程序中生成 pdf 报告。每次我生成pdf时,描述字段都会显示一堆不应该显示的html标签和字段,我只想显示描述字段中的纯文本。有没有人对如何做到这一点有任何建议,还有关于如何将图像添加到 pdf 页面的任何建议?

这是我生成pdf的观点:

@model List<ArdentMC.DHS.COP.Mobile.MVC.Models.Reports>
@{
Layout = "";
}
<!DOCTYPE html>
<html>
<head>
    <div style="color=red; align:center;">UNCLASSIFIED/FOR OFFICAL USE ONLY</div>

</head>
<body>

<table style="width:300px;">
   @foreach (var item in Model)
{
<tr>
<td>@item.Phase</td>
<td>@item.NocNumber</td>
<td>@item.Title</td>
<td>@item.Location</td>
</tr>
    <tr<
    <td></td>
    <td></td> 
    <td>@item.ReportDateText</td>
    <td>@item.Description</td>
    </tr>     
}
</table>                             
    <br /><br /><br /><br /><br />
    <br /><br /><br /><br /><br />
     <div style="color:black; align:center;">US Department of Homeland Security</div>
        <br />
        <div style="color:red; align:center;">UNCLASSIFIED/FOR OFFICAL USE ONLY</div>

</body>
</html>

这是我从中提取信息的模型:

          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Web;

       namespace ArdentMC.DHS.COP.Mobile.MVC.Models
    {
public class Reports
{
    public string NocNumber { get; set; }
    public string Title { get; set; }
    public Nullable<System.DateTime> IncidentDate { get; set; }
    public string ReportDateText { get; set; }
    public string IncidentType { get; set; }
    public Nullable<int> IncidentSubtypeId { get; set; }
    public string IncidentSubtype { get; set; }
    public Nullable<int> PhaseId { get; set; }
    public string Phase { get; set; }
    public string InitialNotification { get; set; }
    public string Location { get; set; }
    public string NocSpotRep { get; set; }
    public string Contributors { get; set; }
    public string Participants { get; set; }
    public string Description { get; set; }
    public Nullable<int> IncidentStateId { get; set; }
    public string IncidentState { get; set; }
    public Nullable<System.DateTime> PublishDate { get; set; }
    public Nullable<System.DateTime> ArchiveDate { get; set; }

    }
}

有人对如何只显示描述文本有一些建议吗?先感谢您。

4

2 回答 2

4

我能够将 @foreach (var item in Model){ @Html.Raw(item.Description) } 添加到我的视图中,并为描述字段呈现正确的代码,这样就没有可查看的标签,只有文本。

于 2014-04-08T23:47:41.060 回答
-1
public ActionResult NotFound() {
    Response.ContentType = "text/html";
    return View();
}
于 2020-10-29T13:54:31.827 回答