2010-12-05 126 views
0

我想將購物車中的商品傳遞給paypal並且收到以下錯誤:paypal ipn在mvc音樂商店問題

對象引用未設置爲對象的實例。

我的代碼是:

<%@頁面語言= 「C#」 的MasterPageFile = 「〜/查看/共享/的Site.Master」 繼承= 「System.Web.Mvc.ViewPage」 %> 地址和支付

<h1>Checkout with PayPal</h1> 

<form id="PayPal" name="PayPal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" /> 

<input type="hidden" name="cmd" value="_cart" /> 
<input type="hidden" name="upload" value="1" /> 
<input type="hidden" name="business" value="[email protected]" /> 

<% foreach (var item in Model.CartItems) 
    { %> 
<%=Html.Hidden("item_name" + item.Count.ToString(), item.Design.Title)%> 
<%=Html.Hidden("amount" + item.Count.ToString(), item.Design.Price)%> 
<%=Html.Hidden("quantity" + item.Count.ToString(), item.Count.ToString())%> 
<%=Html.Hidden("shipping" + item.Count.ToString(), 0)%> 
<%=Html.Hidden("handling" + item.Count.ToString(), 0)%> 
<% } %> 
<input type="image" src="https://fpdbs.paypal.com/dynamicimageweb?cmd=_dynamic-image" align="left" /> 

該錯誤是突出它的foreach em在Model.CartItems中 - 但是在上一頁中,此項目不爲空。似乎這個項目是空的。

+1

您能否請您在控制器中爲這兩個頁面發佈Action代碼。 – 2010-12-05 21:38:56

回答

0

確保您傳遞模型在控制器的描繪這一觀點,並認爲這種模式的CartItems屬性不是null:

public ActionResult Foo() 
{ 
    ShoppingCartViewModel model = FetchYourModelFromSomewhere(); 
    // at this stage model and model.CartItems should not be null 
    return View(model); 
} 

我不知道你是什麼意思說,當該模型在上一頁上不爲空,但控制器操作應始終將模型傳遞給視圖。

+0

這是我的問題,我沒有把我的購物車放到新視圖中。 – rbur0425 2010-12-05 23:02:27