2

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.

3
  • You have HTML outside of the body tag in your view, could this be causing your issue? Commented Apr 4, 2014 at 20:31
  • You also have a mismatch of columns in the rows you are creating within the loop, the first row has 4 columns, the second has only 2. Either add 'colspan=2' to the 2nd row or add more rows. Commented Apr 4, 2014 at 20:33
  • neither of those things made a difference...i tried @html.raw but that didnt seem to work either, i was told i need to render the html some how but dont have enough experience to get it to work.... Commented Apr 4, 2014 at 20:55

2 Answers 2

4

I was able to add @foreach (var item in Model){ @Html.Raw(item.Description) } into my view and that rendered the correct code for the description field so that there are no viewable tags, only text.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Here at SO, an answer has to have an explanation, I will not mark this for deletion ATM, but I urge you to explain your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.