2013-03-14 61 views
0

如何在Razor視圖中硬編碼和顯示xml元素。如何在Razor視圖中顯示xml元素?

我想因爲他們是一個元素中顯示例如以下元素:

<profile> 
    <status>Active</status> 
    <userIdentifier>24d05ce9-7d11-4f06-a9eb-9f33ceac7f91</userIdentifier> 
    <firstName>dd</firstName> 
    <lastName>dasd</lastName> 
    <title>Ms</title> 
    <emailAddress>[email protected]</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> 

怎麼能做到呢?

我知道它可以寫在控件裏面。有沒有更好/更簡單的方法?

+2

到目前爲止你有什麼?在視圖中硬編碼意味着什麼?從哪裏獲得XML?你爲什麼不在你看來用'

@MyVariableHoldingTheXML
'? – nemesv 2013-03-14 15:28:05

+0

它是硬編碼的,想象一個靜態文檔。 – 2013-03-14 15:39:26

回答

4

你可以試試這個:

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

這裏profileXml包含XML字符串。