[英]need to render html from mvc, only displaying htmls tags not text
我正在使用 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; }
}
}
有沒有人對如何只顯示描述文本有一些建議? 先感謝您。
我能夠將 @foreach (var item in Model){ @Html.Raw(item.Description) } 添加到我的視圖中,並為描述字段呈現正確的代碼,因此沒有可查看的標簽,只有文本。
public ActionResult NotFound() {
Response.ContentType = "text/html";
return View();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.