简体   繁体   中英

need to render html from mvc, only displaying htmls tags not text

I am using razorpdf to generate a pdf report in my mvc 4 application. each time I generate the pdf, the description field will display a bunch of html tags and fields that are not supposed to be shown, i just want the plain text from the description field displayed. does anyone have any advice on how to do this, also any advice on how to add an image into the pdf page as well?

this is my view that is generating the 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>

this is my model where the information is getting pulled from:

          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; }

    }
}

does anyone have some advice on how to just get the description text to display? thank you in advance.

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

public ActionResult NotFound() {
    Response.ContentType = "text/html";
    return View();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM