我將數據分成頁面,一個用於菜單,另一個用於彼此的內容。 我已經使用jquery將我從數據庫獲得的數據添加到我的網頁中。 菜單頁面使用ItemModels,內容頁面使用BrandModels。無法將代碼附加到asp.net mvc的其他頁面使用jquery
這是內容頁:
<div id="brand-item">
<% if (blahblah == true){ %>
<a href="<%: brand_url %>" id="brand_id">
<img src="<%:Model.Item[i].Brand.Image%>" width = "85px"/>
</a>
<% } else { %>
<% } %>
</div>
這是我在菜單頁面的嘗試:
if ($("#brand_id").length > 0) {
document.getElementById("brand_id").innerHTML = '<img
src="<%:Model.Item[i].Brand.Image%>" width = "85px"/>';
} else {
document.getElementById("brand-item").innerHTML =
" ";
}
然後是錯誤:BrandModels不包含定義「項目」,並沒有擴展方法'Item'接受第一個參數。 但實際上,我只是想在菜單頁中將這行HTML和asp.net代碼追加到內容頁面。
任何人都可以告訴我如何解決這個問題嗎?
非常感謝和歡迎您的答案。
你的控制器是什麼樣的? – 2012-04-03 08:38:32