我的工作在Razor視圖VB.net模型對象的屬性ASP MVC 4 VB.net如何顯示
我有一個模型:
Public Class ProdSearchModel
Class returnedProduct
Property advertiser_id
Property advertiser_name
Property advertiser_category
Property buy_url
Property currency
Property description
Property image_url
Property name
Property price
Property sale_price
End Class
Public Property query As String
Public Property returnedXML As XElement
Public Property xmlString As String
Public Property listOfProducts = New List(Of returnedProduct)
Sub getXML()
Using client As New WebClient
' Download data as byte array.
Dim arr = client.DownloadString("https://remoteserver.com/product-search?keywords=" & System.Web.HttpUtility.UrlEncode(query))
returnedXML = XElement.Parse(arr)
For Each product In returnedXML...<product>
Dim currentProduct As New returnedProduct
currentProduct.advertiser_id = product...<advertiser-id>
currentProduct.advertiser_name = product...<advertiser-name>
currentProduct.advertiser_category = product...<advertiser-category>
currentProduct.buy_url = product...<buy-url>
currentProduct.currency = product...<currency>
currentProduct.description = product...<description>
currentProduct.image_url = product...<image-url>
currentProduct.name = product...<name>
currentProduct.price = product...<price>
currentProduct.sale_price = product...<sale-price>
listOfProducts.add(currentProduct)
Next
End Using
End Sub
End Class
這拉低一些XML
<advertiser-id>531450</advertiser-id>
<advertiser-name>Cell Phone Shop</advertiser-name> ...
這是所有罰款...
我的控制器看起來是這樣的:
Public Class ProdSearchController
Inherits System.Web.Mvc.Controller
'
' GET: /ProdSearch
Function Index(query As String) As ActionResult
Dim model As New ProdSearchModel With {.query = query}
'model.returnedXML will have the response
model.getXML()
Return View(model)
End Function
End Class
和視圖看起來是這樣的:
@ModelType matrix.ProdSearchModel
@Code
Layout = Nothing
End Code
<!DOCTYPE html>
<html>
<head runat="server">
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
@For Each product In Model.listOfProducts
@product.advertiser_category
Next
<hr />
@*Html.Raw(Model.returnedXML) *@
</div>
</body>
</html>
如果我轉儲XML 「Model.returnedXML」 它都在那裏。
但是,如何引用「listOfProducts」中的每個項目?
也沒有對@product沒有智能感知:
我只是等的ToString,而不是實際的屬性,但如果我在調試模式下運行,我可以看到的數據結構是存在的。
此刻,我只是得到d__aSystem.Xml.Linq.XContainer + d__aSystem.Xml.Linq.XContainer +每一次我看到例如>產品代碼?