【问题标题】:paypal ipn in mvc music store problemmvc音乐商店中的paypal ipn问题
【发布时间】:2011-05-20 15:25:05
【问题描述】:

我正在尝试将购物车中的商品传递给贝宝,但收到以下错误:

对象引用未设置为对象的实例。

我的代码是:

地址和付款

<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="rbur04_1291575642_biz@gmail.com" />

<% 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" />

错误是突出显示 Model.CartItems 中的 foreach 项目 - 但是在上一页中,该项目不为空。似乎该项目即将出现为空。

【问题讨论】:

  • 能否请您为两个页面的控制器中的 Action 方法发布代码。

标签: c# asp.net asp.net-mvc asp.net-mvc-2 paypal


【解决方案1】:

确保您在呈现此视图的控制器操作中传递模型,并且此模型的CartItems 属性不为空:

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

上一页上说模型不为空,但控制器操作应始终将模型传递给视图,我不知道您是什么意思。

【讨论】:

  • 这是我的问题,我没有将购物车传递到新视图中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-08
  • 1970-01-01
  • 1970-01-01
  • 2015-10-04
相关资源
最近更新 更多