HtmlAgilityPack strip html in controller ASP MVC4+

271 views Asked by At

I have an index view which return a list of data. The title parameter contains HTML tags. When I load this view, my title like that <strong>title</strong>.

But I don't need theses tags in this situation, so I'm trying to remove them only for this view. I have read that operation could be done in controller, could you tell me how to do that with HtmlAgilityPack ?

Controller

public ActionResult ArchivePanel(string sortOrder, string currentFilter,string searchString,int? page)
{
...
var alertMap = db.AlertMap.Include(a=>a.AlertLog).Include(a=>a.AlertMode).Include(a=>a.AlertPriority).Include(a=>a.AspNetUsers);
...
return View(alertMap.ToPagedList(pageNumber.pageSize));
}

I need to do this operation on a.AlertLog.AlertTitle value

View

<td>
@Html.DisplayFor(modelItem=>item.AlertLog.AlertTitle)
</td>

Thanks

1

There are 1 answers

1
Justin Harvey On

I would advise you not to use the HtmlAgilityPack for this. This is for manipulating HTML, and in the controller you should not be changing the raw HTML.

Instead, I would suggest using a different view for your page in this situation, that had the look and feel you need in this context. You can factor out the parts of the view that are common with the original view into a shared layout.