如何从剃刀视图中显示XML元素? [英] How to display xml elements from within a Razor view?
本文介绍了如何从剃刀视图中显示XML元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何硬code和显示XML元素从剃刀视图中。
How to hardcode and display xml elements from within a Razor view.
我想因为他们是一个元素中显示例如以下元素:
I'd like to display the below elements for example as they are within a element:
<profile>
<status>Active</status>
<userIdentifier>24d05ce9-7d11-4f06-a9eb-9f33ceac7f91</userIdentifier>
<firstName>dd</firstName>
<lastName>dasd</lastName>
<title>Ms</title>
<emailAddress>test@test.co.uk</emailAddress>
<companyAddress>
<companyName></companyName>
<addressLine1></addressLine1>
<addressLine2></addressLine2>
<addressLine3>Sutton</addressLine3>
<addressLine4>Surrey</addressLine4>
<town>Sutton</town>
<stateOrCounty>Surrey</stateOrCounty>
<postOrZipCode>SM1 5AS</postOrZipCode>
<country>United Kingdom</country>
<region/>
</companyAddress>
<contactAddress>
<addressLine1>30 Park Avenue South</addressLine1>
<addressLine2>New York </addressLine2>
<addressLine3>NY 11010</addressLine3>
<addressLine4>USA</addressLine4>
<town>NY</town>
<stateOrCounty>NY</stateOrCounty>
<postOrZipCode>11010</postOrZipCode>
<country>United States</country>
<region></region>
</contactAddress>
<demographics>
<demographic key="ESOATDropDownList1">
<answer>True</answer>
</demographic>
</demographics>
</profile>
如何能做到?
我知道它可以控制内被写入。有没有更好/更简单的方法呢?
I know it can be written inside a control. Is there any better/easier approach?
推荐答案
您可以试试这个:
@{
var profileXml = @"
<profile>
<!-- your xml -->
</profile>";
}
<pre>
@Html.Raw(Html.Encode(profileXml))
</pre>
下面 profileXml
包含XML字符串。
Here profileXml
contains the XML string.
这篇关于如何从剃刀视图中显示XML元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文