xml - 如何从 Razor View 中显示 xml 元素?

标签 xml asp.net-mvc razor

如何在 Razor View 中硬编码和显示 xml 元素。

例如,我想显示以下元素,因为它们在一个元素内:

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

这怎么可能呢?

我知道它可以写在一个控件里面。有没有更好/更简单的方法?

最佳答案

你可以试试这个:

@{
   var profileXml = @"
<profile>
    <!-- your xml -->
</profile>";
}
<pre>
    @Html.Raw(Html.Encode(profileXml))
</pre>

此处 profileXml 包含 XML 字符串。

关于xml - 如何从 Razor View 中显示 xml 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15413183/

相关文章:

java - 获取 xml 元素的字节/字符偏移量

html - 传递外部 .xml 文件的内容并保留样式标签

.net - System.Web.Caching.Cache 在 ASP.Net MVC 应用程序中有意义吗?

c# - 如何在单击按钮时将数据从 View 发送到 Controller

c# - 从强类型 Razor View 收集数据

asp.net - 在布局中添加 PartialView

php - 将 YouTube 播放列表中的所有视频 ID 获取到 PHP 数组中

Python xml绝对路径

ASP.NET Core MVC 健康检查失败

url - 如何将带有@ url.action的参数传递给 Controller