简体   繁体   中英

ASP.NET MVC - Using XDocument - br tag displaying as text on screen

I have an XML document which contains multiple properties and each property has a summary description node. The summary description nodes sometimes contain html
tags that I'd like to be used to actually create a line break on the page, but the
tags are currently being displayed as text. I'm currently using XDocument in the contr to grab the value of the summaryDescription node and then passing this to the view via a view model.

XML

<summaryDescription>
A very spacious first floor four bedroom apartment situated in a convenient location. The apartment has a very impressive accommodation comprising main entrance foyer leading to hall, formal lounge, well appointed kitchen breakfast area and TV common room, family bathroom and en-suite shower room.<br/><br/>
</summaryDescription>

Controller

var query = (from props in xml.Descendants("property")
             select new PropertyResult
             {
                 Description = props.Element("summaryDescription").Value,
                 PriceText = props.Element("pricetext").Value,
                 Image = "http://www.dezrez.com/estate-agent-software/ImageResizeHandler.do?&photoID=1&AgentID=1239&BranchID=1976&Width=500&PropertyId=",
              }).ToArray();

return View(new ResultsViewModel { Property = query });

As you can see the summaryDescription xml node has two line breaks at the end but these are currently being displayed as text on the page. If anyone could help me with forcing the page to see the
tags as html tags, I'd be very grateful.

Thanks in advance!

在您的剃刀视图标记中,在您的媒体资源上使用此扩展方法。

public static IHtmlString EscapeHTML(this HtmlHelper htmlHelper, string value) { return new HtmlString(value.ToString()); }

@Html.EscapeHTML(Model.Property)

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